-
Notifications
You must be signed in to change notification settings - Fork 10
Add *python-call-mode* in config: allow using a separate thread to call python #23
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
Conversation
Running the scripts in |
Proof of concept: Wrapping the body of pycall inside |
dd3a17f
to
e18dd82
Compare
I think :dedicated and :standard are OK. |
e18dd82
to
cd2e6ea
Compare
This should minimize deadlocks CCL. Apparantly, implementing pystop correctly for :dedicated-thread might be more involved.
With the way calls are made to the dedicated thread via dedicated-thread-utils.lisp, there's not much performance to be gained beyond what 5ce8660 enables. PY4CL2-CFFI> (time
(loop for i below 10000 do (funcall/dedicated-thread #'pycall "str" i)))
0.253 seconds of real time
NIL
PY4CL2-CFFI> (time
(loop for i below 10000 do (funcall/dedicated-thread #'null i)))
0.232 seconds of real time
NIL
PY4CL2-CFFI> (time
(loop for i below 10000 do (funcall/dedicated-thread #'null-pointer)))
0.189 seconds of real time
NIL This is 10+ time slower than when I think this PR is ready to be merged. Perhaps in the future, if someone discovers a better method of sync-ing or interthread calls, this might be optimizable. |
Fixes #11
This PR adds the variables
py4cl2-cffi/config:*python-call-mode*
andpy4cl2-cffi:+python-call-mode+
, along with appropriate changes to ecase on these variables.The central idea is that when python call mode is
:single-threaded
, py4cl2-cffi starts the python interpreter in its own separate thread. All calls to python viapyvalue pycall
and friends occur through this thread. This allows libraries like matplotlib to assume that there is a single thread.To use this functionality -
Note that the decision to use a separate thread or otherwise needs to be made before python initialization aka pystart.
This also makes the
single-threaded/
directory unnecessary.Two main concerns with this PR include:
:dedicated
and:standard
instead of:single-threaded
and:multi-threaded
sound more informative. I'd be happy to hear any opinions from repository watchers or anyone passing by.:single-threaded
mode is about 10 times slower than:multi-threaded
. I'm also yet to benchmark:multi-threaded
against the existing code. Ideally, this should not incur a penalty, since we are trying to push the decisions to compile time instead of runtime.