pyscripter 689 Posted November 1, 2023 There have been a lot of questions in this forum about running python code in threads using Python4Delphi. I have created a comprehensive guide in this Wiki topic. 3 Share this post Link to post
Pat Foley 51 Posted November 1, 2023 Is a 2006 Programming Python by Mark Lutz still worth reading? Then use your guide to learn how use threads with Python. Thanks Share this post Link to post
pyscripter 689 Posted November 1, 2023 (edited) 2 hours ago, Pat Foley said: Is a 2006 Programming Python by Mark Lutz still worth reading? Python 3 was released in 2008. I would read something more recent that is based on Python 3. pamoroso/free-python-books: Python books free to read online or download (github.com) Edited November 1, 2023 by pyscripter 1 Share this post Link to post
David Heffernan 2348 Posted November 1, 2023 My recollection of Lutz's work is that Learning Python is the book of his to read. As for the Python 2 vs 3 distinction, I'd be less worried about that. That's more about syntax details than concepts. A really good work written for Python 2 is better than an average work for Python 3. The differences between 2 and 3 aren't significant conceptually. 1 Share this post Link to post
maomao2028 0 Posted April 21 It seems ThreadPythonExec does not work. and memory leak occurs procedure TForm1.Button2Click(Sender: TObject); begin ThreadPythonExec( procedure begin GetPythonEngine.Execstring('print(10)'); end); end; Share this post Link to post
pyscripter 689 Posted April 22 @maomao2028 Works fine here without memory leaks. See attached project. Note the use of DelayWrites := True in the PythonGUIInputOutput and the calls to TPythonThread.Py_End_Allow_Threads and TPythonThread.Py_Begin_Allow_Threads. Demo01.zip Share this post Link to post
maomao2028 0 Posted April 30 On 4/22/2024 at 6:56 PM, pyscripter said: @maomao2028 Works fine here without memory leaks. See attached project. Note the use of DelayWrites := True in the PythonGUIInputOutput and the calls to TPythonThread.Py_End_Allow_Threads and TPythonThread.Py_Begin_Allow_Threads. Demo01.zip Thanks for your help, now the thread is running fine Share this post Link to post