Dmitry72 1 Posted August 23, 2023 Dear All, PythonEngine is a singleton by design and wrapper of pythonXXX.dll (which is part of Python for Windows). I'm unable to run 2 and more TPythonEngine per VCL application and I believe this is a restriction applied by the DLL. So, the pythonXXX.dll is a single threaded library. Please advise on how we can work-around this issue? Thanks in advance. Share this post Link to post
pyscripter 689 Posted August 23, 2023 (edited) 2 hours ago, Dmitry72 said: So, the pythonXXX.dll is a single threaded library. Why do you conclude that? If you want to run python code in threads, please study Demo 33 and search for related content in this forum (there is lots). Also google for "Global Interpreter Lock". Edited August 23, 2023 by pyscripter Share this post Link to post
Dmitry72 1 Posted August 23, 2023 I'm apologizing for my question formulation. Threads are good. But those threads are inside of Python session and share the same environment. They can't be used for creating sessions. I state that pythonXXX.dll is a single process library and it can't be used for creating more than one session per VCL process application. Can you sir, confirm that, please. Share this post Link to post
pyscripter 689 Posted August 23, 2023 (edited) 1 hour ago, Dmitry72 said: pythonXXX.dll is a single process library You cannot load multiple versions of any dll simultaneously in a single process. 1 hour ago, Dmitry72 said: But those threads are inside of Python session and share the same environment. If you study Demo 33, you will see that this is not necessarily the case. Edited August 23, 2023 by pyscripter Share this post Link to post
David Heffernan 2345 Posted August 23, 2023 Next release of Python supports per interpreter GIL which sounds exciting. Share this post Link to post
Dmitry72 1 Posted August 23, 2023 procedure TSortThread.ExecuteWithPython; var pyfunc: PPyObject; begin ...... if Assigned(fScript) then ExecStrings(fScript); pyfunc := FindFunction( ExecModule, fpyfuncname); if Assigned(pyfunc) then try EvalFunction(pyfunc,[NativeInt(self),0,FSize]); except end; I can see that TPythonThread can Exec script or find a Function in global script and Exec it. But how can I use PythonInputOutput1 to interact with the Thread? How can I get a user interact with the Thread's script? Share this post Link to post