Jump to content
Registration disabled at the moment Read more... ×
Sign in to follow this  
Martybartfast

Can't print from Python script thread to Delphi main thread

Recommended Posts

I emailed @pyscripter about an issue I was having with getting a dynamically created TPythonThread to print to a dynamically created TPythonInputOutput. He suggested I should post here.

I've tried some of the suggested ideas, but alas still no luck with print() from a threaded script appearing on the main thread memo.

 

I have now created a minimal project with my code, see attached. Can anyone explain what I'm doing wrong?! The script seems to run (the for loop reacts as expected), but I just can't see the Print output. Much appreciate any help, thank you!

P4D Showtime test.zip

Share this post


Link to post

Output redirection is not supported with emNewInterpreterOwnGIL.

 

See other threads with a discussion of the limitations of that mode in this forum.

Share this post


Link to post

@Martybartfast

Actually there is an easy solution:

 

Replace TPyThread.ExecuteWithPython with

procedure TPyThread.ExecuteWithPython;
// Run the script
begin
  TPythonModule(PyEngine.IOPythonModule).MultInterpretersSupport := mmiPerInterpreterGIL;
  TPythonModule(PyEngine.IOPythonModule).InitializeForNewInterpreter;
  PyEngine.DoRedirectIO;
  PyEngine.ExecString(FScript);   // Run Python script
end;

and printing should work.

Edited by pyscripter

Share this post


Link to post

@Martybartfast Support for output redirection from sub-interpreters has been committed.    So with the latest version you do need the above workaround.

Edited by pyscripter

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  

×