Jump to content
Sign in to follow this  
Nefari0

don't works import pandas or openpyxl in TPythonThread (delphi)

Recommended Posts

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

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 by pyscripter

Share this post


Link to post
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 by Nefari0

Share this post


Link to post

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 by Nefari0

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  

×