Martybartfast 1 Posted 22 hours ago 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
pyscripter 796 Posted 22 hours ago 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 1 Posted 21 hours ago Ahhh, yes. If I set ThreadExecMode := emNewState; then I see print output. Hummmm... need to think what to do then. Share this post Link to post
pyscripter 796 Posted 20 hours ago (edited) @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 20 hours ago by pyscripter Share this post Link to post
pyscripter 796 Posted 19 hours ago (edited) @Martybartfast Support for output redirection from sub-interpreters has been committed. So with the latest version you do need the above workaround. Edited 19 hours ago by pyscripter Share this post Link to post
Martybartfast 1 Posted 3 hours ago @pyscripterAwesome stuff!!! Works perfectly now. Thank you so much, and thanks for making such a great set of components Share this post Link to post