Jump to content
Sign in to follow this  
Dmitry72

Unable to run 2 TPythonEngine per VCL application

Recommended Posts

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
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 by pyscripter

Share this post


Link to post

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
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 by pyscripter

Share this post


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

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  

×