Add support for asynchronous callbacks, python polling of lisp, multiple python processes#36
Add support for asynchronous callbacks, python polling of lisp, multiple python processes#36ajberkley wants to merge 5 commits into
Conversation
|
Heh, of course I made the PR with a parens error... sorry. Passes tests and actually compiles now. |
…ple python processes parens fix and indentation fixes
|
I tried it today. After incorporating a fix for iterate, I can confirm that most tests pass. Some still fail. But this looks too large a change for a single commit. I will probably sleep on it for some time and commit it part by part. Thanks for your work! |
|
Added a fix for deleting the numpy pickle files which I had broken. Is there a reason we don't just write the pickled format across the stream to the python process? It would avoid this complexity... |
|
For tests, is it that they are not passing on other implementations? I only tried with sbcl... I can run with other ones if that is the issue --- since the CI test runner seems broken I can't learn it from there. |
I suspect the way things are the way they are is that the approach of creating a file is what occurred to me back then. I think the secondary reason is that stdin/stdout/stderr are text streams rather than binary. If numpy is present, one could perhaps create and maintain another binary stream. (Feel free to suggest other approaches!)
With ba09cca, the CI works again. sbcl is fine as the minimal target. Once it works on sbcl, we can test on ccl, and possibly ecl. Looking at the latest CI, the tests are passing. Pystart/stop might require some minor fixes to make it to work on repeated calls without raising the python error |
|
I started gui-apps branch to incorporate the fixes and changes from this PR. Based on the things I looked at so far, mainly
|
I agree, you are right that it is simpler to just mark it invalid and shut it down and not reuses it.
A semaphore is fine but it communicates the wrong idea. You have one resource and only one thread can use it at a time, so a mutex is clearer. |
This is because the test is wrong. The (let ((i i)) ...) needs to be outside the (lambda ()). I'm happy to discuss further if this isn't clear :) Threading is tricky business! |
|
Thanks! I have fixed the test: digikar99/py4cl2-tests@abed9ff About I'm continuing the refactor in https://github.com/digikar99/py4cl2/pull/37/commits. Let me know if you are okay with the authorships! I can then base the main changes concerning the gui apps onto the refactor. |
|
I wonder if the purpose of the timing code in src/callpython.lisp may be served by the profiling capabilities of SLIME/implementation. For example, SBCL has both the deterministic profiler as well as the statistical profiler. For the task at hand -- measuring the performance of |
|
More questions:
Also, the way this is implemented, if there is an error -- say PyQt6 is not installed, or some syntax error, or some future error -- during the execution of (raw-py-exec/no-return "import PyQt6_example; PyQt6_example.start_app(try_process_message);")then it'd appear as a response to |

This is obviously a pretty big change, in particular the multiple python processes one. It passes all the py4cl2-tests though!
I'm not sure how the original code passed all the tests, though --- the with-python-output relied on timing alone which doesn't work perfectly... even after flushing stuff on both sides, there's still time for the data to not reach the lisp side before we exit... relying on a sleep call is not reliable. So I added something a bit more complex but it works 100% of the time.
I haven't started using this heavily, though, so there's absolutely no rush to work through merging this or looking through the changes. I'm just opening this PR so you know where I am. In my cl-matplotlib repo, you can see it running an animated graph updating from some python code while also sending callbacks into lisp as you press buttons which then callback into python to update the graph (the PyQt python side is fragile as I haven't put any time into it yet, so if you close the main window python dies horribly some amount of the time).
Below picture the sine wave is being animated from python code, the button is calling back into lisp and updating the plot.