Jump to content

pyscripter

Members
  • Content Count

    983
  • Joined

  • Last visited

  • Days Won

    62

Everything posted by pyscripter

  1. Will this not cause an issue with earlier DELPHI versions?
  2. pyscripter

    Delphi 12.2 available for download

    Forgot to do that. How can I fix it now? Update: Deleted Parnassus entries from Registry and now it works. Very annoying.
  3. pyscripter

    Memory Leak creating Engine at runtime?

    You can set ReportMemoryLeaksOnShutdown to True to see whether there are leaks on the Delphi side. Loading and unloading the python dll multiple times is not a good idea. There is no guarantee that it will release all allocated memory when it unloads and it does not unload all other dlls loaded by python. It was designed to be loaded once in a single process. And there is no need to do that. Your program will be faster and leaner if you reuse the python dll.
  4. pyscripter

    Possible memory leak

    The GetIt version is created by Embarcadero based on a p4d fork. Eventually the fixes will be added to the Embacadero fork, but then it may take some time for the GetIt installation to be updated. Using the pyscripter/python4delphi: Free components that wrap up Python into Delphi and Lazarus (FPC) (github.com) repo will probably get you the latest fixes much faster.
  5. pyscripter

    TComponent.Create() equivalent in Python script?

    You can create instances of classes in the "pythonic" way: myform = Form() TForm.Create() is not supported (TForm is exposed in python as Form).
  6. pyscripter

    I/O doesn't work

    OnData is called from a thread. You need to change it to: procedure TForm2.OnData(Sender: TObject; const Data: string); begin TThread.Synchronize(nil, procedure begin Memo1.Lines.Add(Data); //No Memo1.Lines.Add('2'); //No end); end; Also set DelayWrites to False. DelayWrites only makes sense with TPythonGUIInputOutput. With the above two changes your code works as expected.
  7. pyscripter

    I/O doesn't work

    Can you post a zip file with your project?
  8. pyscripter

    I/O doesn't work

    Use the OnSendUniData event to process data sent by the python engine.
  9. pyscripter

    I/O doesn't work

    TPythonGUIInputOutput works with a linked memo. Use TPythonInputOutput instead.
  10. pyscripter

    Parsing a python collection into a delphi collection

    As you can see from your output AddressNumber is a string (as well as the other fields). You need to convert it to an integer.
  11. pyscripter

    Parsing a python collection into a delphi collection

    I am not exactly sure what you are trying to do, Also the 4th line in your script is doing nothing since you are assigning a new value in the next statement. However, if you want to access these values in Delphi and store them say in a Delphi data structure, the easiest way is using VarPyth. For instance to access the AddressNumber, after running the above script, you use something like: var AddressNumber := MainModule.od[0]['AddressNumber'];
  12. pyscripter

    Is there a Delphi "subprocess" library?

    You can always use the this python module from Delphi using P4D . One of the most advanced such Delphi functions in the Jcl unit JclSysUtils. Look at ExecuteCmdProcess and the various Execute overloads. It uses overlapped IO for super efficient redirection of the produced output, instead of using a special thread or a timer. These functions are also suitable for execution from a task/thread, if you do not want to block the main thread. The unit pyscripter/Source/uSysUtils.pas at master · pyscripter/pyscripter (github.com) extends the jcl functions to allow for an stdin pipe, customized environment variables and a buffered raw output.
  13. pyscripter

    Python freezes when running a certain script

    You don't need to create and destroy zPythonDelphiVar in every thread. Add zPythonDelphiVar to the form: object zPythonDelphiVar: TPythonDelphiVar Engine = PythonEngine1 Module = '__main__' VarName = 'result' Left = 64 Top = 120 end Then modify ExecuteWithPython to procedure TPythonThread_Test1.ExecuteWithPython; var i: Integer; begin fOutputs := TStringList.Create; for i := 1 to 10000 do begin GetPythonEngine.ExecString(UTF8Encode(Script)); GetPythonEngine.CheckError; fOutputs.Add(Form1.zPythonDelphiVar.Value); end; end; and it should work as you would expect. And since you mentioned it, a fellow Brazilian @lmbelo Lucas Belo, is a major contributor to P4D and would certainly be in a position to help.
  14. pyscripter

    Python freezes when running a certain script

    You never explained what is the problem.
  15. pyscripter

    Python freezes when running a certain script

    @djxandytche "Here is my code, please check and find the bugs" is not a good way to get support. Why should anyone spend one hour of their time, understanding and debugging your code? You say you are beginner in Python. Then why do you start by running python code in threads, which requires some expert knowledge? Do you realize that there is no performance benefits in running python code in threads like this? They will be executed sequentially, thanks to the GIL.
  16. For Delphi is here: Fundamental Syntactic Elements (Delphi) - RAD Studio (embarcadero.com) and for fpc Identifier - Free Pascal wiki.
  17. arr := np.&ones(VarPythonCreate([N, N]), np.float64) You do not need the &. It is only needed when using a keyword such as "array" (and Delphi does not need it even then).
  18. Also, since you are interested in image manipulations, have a look at this thread: Place image in a TImage - Python4Delphi - Delphi-PRAXiS [en] (delphipraxis.net)
  19. np.float64 corresponds to pascal double. Use double instead of single. Use BuiltinModule.float instead of BuiltinModule.int. For multidimensional arrays you need to use the ndim and shapes fields of the Buffer structure. An array of Py_ssize_t of length ndim indicating the shape of the memory as an n-dimensional array. Note that shape[0] * ... * shape[ndim-1] * itemsize MUST be equal to len. If you know the dimensions of the array you can directly cast to an equivalent pascal multidimensional array.
  20. pyscripter

    Python freezes when running a certain script

    Have you read the docs and the limitations of using subinterpreters? Initialization, Finalization, and Threads — Python 3.12.4 documentation Also the docs for the PyInterpreterConfig structure? pandas and numpy probably do not support running in subinterpreters. I suggest that you forget about sub-interpreters unless you know very well what you are doing. But then you are on your own.
  21. pyscripter

    Python freezes when running a certain script

    With SafePyEngine you do not get that choice. It is equivalent to emNewState, which is by far the most common use case.
  22. pyscripter

    Python freezes when running a certain script

    @djxandytche Your code for running python code in threads is reinventing the wheel and the result is evidently incorrect. Just follow the guidelines at PythonThreads · pyscripter/python4delphi Wiki (github.com) paying attention also to the preparation section. Also, have a close look also to Demos 33 and 36.
  23. pyscripter

    DelphiVCL TreeView OnCustomDrawItem

    A fix has been applied to P4D. Please check.
  24. pyscripter

    PyScripter - Integration with LLM

    The forthcoming version of PyScripter will have built-in integration with LLM. See the blog post for a taste of the functionality provided.
  25. pyscripter

    PyScripter - Integration with LLM

    I am aware of that. This is due Sourceforge changing the way you download files directly. Will work with the next update for this one just download from PyScripter - Manage /PyScripter-v5.0 at SourceForge.net and install.
×