-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathremotequeue.py
31 lines (27 loc) · 964 Bytes
/
remotequeue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from multiprocessing.managers import BaseManager
from multiprocessing import Queue
import random
PORT = 8989
def get(ip, authkey):
''' gets a remote queue on another ip '''
class RManager(BaseManager):
''' manager which connects to a remote queue '''
pass
RManager.register('getQueue')
current_manager = RManager(address=(ip,PORT), authkey=authkey)
current_manager.connect()
return current_manager.getQueue()
def make(authkey, public=True):
''' makes a remote queue and returns it '''
class QManager(BaseManager):
''' manager of a remote queue '''
pass
queue = Queue()
QManager.register('getQueue', callable=lambda:queue)
ip = '0.0.0.0' if public else 'localhost'
qm = QManager(address=(ip, PORT), authkey=authkey)
qm.start()
tokens = [random.choice('abcde') for x in range(14)]
random_token = 'x'.join(tokens)
globals()['raNdDOmHAkkC82492'] = qm
return queue