Martybartfast 2 Posted yesterday at 02:51 PM 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 yesterday at 02:58 PM 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 2 Posted yesterday at 03:53 PM 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 yesterday at 04:55 PM (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 yesterday at 04:57 PM by pyscripter Share this post Link to post
pyscripter 796 Posted yesterday at 06:31 PM (edited) @Martybartfast Support for output redirection from sub-interpreters has been committed. So with the latest version you do need the above workaround. Edited yesterday at 06:32 PM by pyscripter Share this post Link to post
Martybartfast 2 Posted 11 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
Martybartfast 2 Posted 7 hours ago BTW for anyone else doing ThreadExecMode := emNewInterpreterOwnGIL; and using a module, do make sure in your module you set this property: MultInterpretersSupport := mmiPerInterpreterGIL; That cause me a bit of head scratching for a while! 1 Share this post Link to post