-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
boa: support running Python code in non-blocking way #602
Conversation
It uses the Node.js worker_threads to start new thread to run Python functions. Note that, we share the same Python interrupter.
@FeelyChau Just mark this PR be ready for review :) |
Occurred the following error if running
|
This is addressed, the sub-thread would call to the |
@FeelyChau See https://github.com/alibaba/pipcook/pull/602/checks?check_run_id=1192579536, it seems failed by daemon tests which are not related to this PR. |
OK, I'll check it out. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
packages/boa/src/core/object.cc
Outdated
if (_ownership == nullptr) { | ||
return true; | ||
} else { | ||
bool owned = _ownership->getOwned(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems not thread-safe here.
packages/boa/src/core/object.h
Outdated
private: | ||
mutable std::mutex _mtx; | ||
PyObject *_pyobject; | ||
bool _owned; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use std::atomic_flag
instead to improve performance.
Co-authored-by: feely <feely@outlook.com>
LGTM. |
This PR uses the Node.js
worker_threads
to start a new thread to run Python functions, and addSharedPythonObject
to share(not copy) the Python object in sub-threads.The following is an experimental API usage(example):
TODO
SharedPythonObject
twice and multiple times on a same object.avoid crash(segfault) if theownershipId
is invalid.