-
Notifications
You must be signed in to change notification settings - Fork 11
/
util.py
35 lines (27 loc) · 1.02 KB
/
util.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
31
32
33
34
35
import multiprocessing.managers
import config
class BaseManager(multiprocessing.managers.BaseManager):
"""A simple modified BaseManager from multiprocessing
This adds three classmethods.
"""
authkey = getattr(config, 'authkey', "Not very random")
socket = None
@classmethod
def connect_to(cls):
"""Connects to a remote already running manager and returns it."""
manager = cls(address=cls.socket, authkey=cls.authkey)
manager.connect()
return manager
@classmethod
def start_server(cls):
"""Starts a manager server in the calling thread and blocks until
shutdown from another thread in some way."""
manager = cls(address=cls.socket, authkey=cls.authkey)
server = manager.get_server()
server.serve_forever()
@classmethod
def launch_process(cls):
"""Launches a process and returns the manager associated."""
manager = cls(address=cls.socket, authkey=cls.authkey)
manager.start()
return manager