DaveLaneCA 0 Posted December 7, 2020 I am adding the capability to run python code to my existing astrophysics application so I can leverage the incredible python libraries available. When I run simple python scripts, all is fine. Whenever I run anything complicated that imports other code (example 'numpy'), the script hangs. The same script runs fine using any of the demo apps (demo01, for example). I have diagnosed the problem to being thread- related. I run all my existing (native delphi) calculations in a TThread so that the program's user interface is not blocked (no VCL calls are made from the thread). When I run the complicated script from my existing TThread, it hangs (can be duplicated by just an "import numpy as np" line). If I run the same code from the application's main thread, it works fine. Any idea why this would be OR how to run a python script in a thread OR how to run python code in a way that does not block the primary thread. --- Dave Share this post Link to post
David Heffernan 2345 Posted December 7, 2020 thread safe? · Issue #47 · pyscripter/python4delphi · GitHub Share this post Link to post
DaveLaneCA 0 Posted December 7, 2020 Yes David - I read that. I am not trying to run more than one python thread in an app (instance of pythonxx.dll). I understand that Indy, in his example, would mean multiple python threads. Share this post Link to post
pyscripter 689 Posted December 7, 2020 Have you studied demo33 and used TPythonThread? Share this post Link to post
David Heffernan 2345 Posted December 7, 2020 10 minutes ago, DaveLaneCA said: Yes David - I read that. I am not trying to run more than one python thread in an app (instance of pythonxx.dll). I understand that Indy, in his example, would mean multiple python threads. Doesn't matter how many threads you use. It's an issue with the Python GIL that requires special treatment with threads. 1 Share this post Link to post
DaveLaneCA 0 Posted December 7, 2020 12 minutes ago, pyscripter said: Have you studied demo33 and used TPythonThread? I have looked at them, but did not think the additional complexity would be needed if I only intended one python thread within the application. If you say that a single (threaded) python script still needs to use TPythonThread, I'll look give it ago. Share this post Link to post