Skip to content

Commit d5697ea

Browse files
committed
Update mp_manager.
1 parent 165d0e0 commit d5697ea

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

law/util.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import random
4545
import threading
4646
import multiprocessing
47+
import multiprocessing.managers
4748
import io
4849
import shlex
4950
import inspect
@@ -71,9 +72,6 @@
7172
io_lock = threading.Lock()
7273
console_lock = threading.Lock()
7374

74-
# globally usable manager for mp objects
75-
mp_manager = multiprocessing.Manager()
76-
7775

7876
class NoValue(object):
7977

@@ -101,6 +99,21 @@ def __str__(self):
10199
no_value = NoValue()
102100

103101

102+
def MPManager(**kwargs):
103+
"""
104+
Factory function identical to :py:func:`multiprocessing.Manager` but allows for additional
105+
arguments to be forwarded to the underlying :py:class:`multiprocessing.managers.SyncManager`.
106+
"""
107+
kwargs.setdefault("ctx", multiprocessing.context._default_context.get_context())
108+
manager = multiprocessing.managers.SyncManager(**kwargs)
109+
manager.start()
110+
return manager
111+
112+
113+
# globally usable manager for mp objects
114+
mp_manager = MPManager(address=("localhost", 0))
115+
116+
104117
def rel_path(anchor, *paths):
105118
"""
106119
Returns a path made of framgment *paths* relativ to an *anchor* path. When *anchor* is a file,

0 commit comments

Comments
 (0)