Jump to content
Sign in to follow this  
DaveLaneCA

Running complicated python code from existing TThread hangs

Recommended Posts

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

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
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.

  • Like 1

Share this post


Link to post
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×