Nefari0 0 Posted December 10, 2022 Hello! when I try to run "import pandas" or "import openpyxl" in TPythonThread I got stopped thread without any errors but in OwnThreadState Tpythonengine it works example of code PyCodeList.Add('import pandas'); InitThread(emNewInterpreter, PyCodeList); - thread was stopped after few seconds without any errors if I don't import pandas or openpyxl then other commands and modules are working good in this thread example of working code PyCodeList.Add('import pandas'); GetPythonEngine.ExecStrings(PyCodeList); - all ok sorry for my english Share this post Link to post
pyscripter 694 Posted December 10, 2022 (edited) Please post questions regarding P4D to the Third Party P4D support forum. What is this InitThread? Using python threads requires deep knowledge of the Python API and the complexities of GIL. If do have to use threads, please study Demo 11 and the related posts in the P4D forum Showing results for 'Py_Begin_Allow_Threads'. - Delphi-PRAXiS [en] (delphipraxis.net) Edited December 10, 2022 by pyscripter Share this post Link to post
Nefari0 0 Posted December 10, 2022 (edited) 18 minutes ago, pyscripter said: Please post questions regarding P4D to the Third Party P4D support forum. Thanks I got it 18 minutes ago, pyscripter said: What is this InitThread? It´s the procedure that create threads and executes python scripts. I got it from demo33 p4d I try to use python threads to avoid blocking the UI. Edited December 10, 2022 by Nefari0 Share this post Link to post
Nefari0 0 Posted December 10, 2022 (edited) I decided to stop using pandas in Python inerpreter and return list to delphi for processing it in delphi instead of python´s panda And this is what I got: data in python data=[['123',456],['321',654]] sendrawrada(data) and I got it in delphi with function function TMainForm.send_raw_data( pself, args : PPyObject ) : PPyObject; cdecl; var R: byte; data: PPyObject; row: array of variant; col: array of variant; i,j:word; rowSize:byte; colSize:byte; resstr:string; begin with GetPythonEngine do begin R:=PyArg_ParseTuple(Args, 'O:sendrawdata', @data); if R<>0 then begin application.ProcessMessages; row:=pyobjectasvariant(data); rowSize:=Length(row); for i:= 0 to rowSize-1 do begin col:=row; colSize:=Length(col); resstr:=''; for j:=0 to colSize-1 do begin resstr:=resstr+vartostr(col[j]); end; resmemo.Lines.Add(resstr); end; SendMessage(resmemo.Handle, WM_VSCROLL, SB_BOTTOM, 0); Result := ReturnNone; end else Result := nil; end; end; here is the test code Edited December 10, 2022 by Nefari0 Share this post Link to post