Skip to content

Commit b75bf76

Browse files
committed
Merge pull request #223 in LCL/wolframclientforpython from bugfix/gvisor-lock to master
* commit 'c1eb832c359ba152310bb1128da292e6f6d58d2c': adding warning there is no need for context manager adding a dummy context manager
2 parents 0504509 + c1eb832 commit b75bf76

3 files changed

Lines changed: 28 additions & 13 deletions

File tree

wolframclient/serializers/encoder.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import pkg_resources
99

1010
from wolframclient.serializers.utils import safe_len
11-
from wolframclient.utils import six
1211
from wolframclient.utils.api import multiprocessing
1312
from wolframclient.utils.dispatch import Dispatch
1413
from wolframclient.utils.functional import composition, is_iterable, iterate, map
@@ -64,18 +63,10 @@ def _update_plugins(self):
6463
raise e
6564
self.plugins_registry = defaultdict(list)
6665

67-
if not six.JYTHON:
68-
# global lock to avoid multiple dispatcher updating in multithreaded programs.
69-
_lock = multiprocessing.Lock()
66+
# global lock to avoid multiple dispatcher updating in multithreaded programs.
7067

71-
def update_dispatch(self):
72-
with self._lock:
73-
self._update_dispatch()
74-
self._update_plugins()
75-
76-
else:
77-
78-
def update_dispatch(self):
68+
def update_dispatch(self):
69+
with multiprocessing.Lock():
7970
self._update_dispatch()
8071
self._update_plugins()
8172

wolframclient/utils/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
PackedArray="wolframclient.utils.packedarray.PackedArray",
139139
)
140140

141-
multiprocessing = API(Lock="multiprocessing.Lock")
141+
multiprocessing = API(Lock="wolframclient.utils.lock.Lock")
142142

143143
PIL = API(Image="PIL.Image.Image", fromarray="PIL.Image.fromarray", open="PIL.Image.open")
144144

wolframclient/utils/lock.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from __future__ import absolute_import, print_function, unicode_literals
2+
3+
import warnings
4+
5+
try:
6+
import multithreading
7+
8+
_lock = multithreading.Lock()
9+
10+
def Lock():
11+
return _lock
12+
13+
14+
except (ImportError, OSError):
15+
16+
# JYTHON is raising an ImportError when running "import multithreading"
17+
# GVisor is raising an OSError when running "multithreading.Lock()" because the feature is not implemented
18+
19+
from contextlib import contextmanager
20+
21+
@contextmanager
22+
def Lock():
23+
warnings.warn("Lock is not implemented in the current interpreter.", RuntimeWarning)
24+
yield

0 commit comments

Comments
 (0)