Skip to content

Commit

Permalink
FIX race in python imports
Browse files Browse the repository at this point in the history
  • Loading branch information
spirali committed Jul 26, 2018
1 parent f93d94e commit 0f48f01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion python/loom/wside/core.py
@@ -1,6 +1,6 @@
import cloudpickle
import loom_c

import threading

class Context:

Expand Down Expand Up @@ -41,3 +41,11 @@ def execute(fn_obj, data, inputs, task_id):
return fn_obj(context, *inputs)
else:
return fn_obj(*inputs)


unpickle_lock = threading.Lock()


def unpickle(data):
with unpickle_lock:
return cloudpickle.loads(data)
4 changes: 2 additions & 2 deletions src/libloomw/python/core.cpp
Expand Up @@ -38,12 +38,12 @@ void loom::ensure_py_init() {
PyObject* loom::deserialize_pyobject(const void *mem, size_t size)
{
// Get cloudpickle
PyObject *cloudpickle = PyImport_ImportModule("cloudpickle");
PyObject *cloudpickle = PyImport_ImportModule("loom.wside.core");
if(!cloudpickle) {
return nullptr;
}

PyObject *loads = PyObject_GetAttrString(cloudpickle, "loads");
PyObject *loads = PyObject_GetAttrString(cloudpickle, "unpickle");
Py_DECREF(cloudpickle);

if(!loads) {
Expand Down

0 comments on commit 0f48f01

Please sign in to comment.