Jump to content

Soulflesh

Members
  • Content Count

    16
  • Joined

  • Last visited

Posts posted by Soulflesh


  1. Hi FabDev,

     

    In my estimation, this is not a good idea due to the lack of parallelisation with Python. We also use the TMS Scripter for web applications (f.e. https://help.clarc-software.de/display/CD7/WEB+VALIDATION+Arbeitsbereich). Here, however, you also reach the limits very quickly as soon as you use the generic classes in the scripter. These require a lot of performance and about 1MB per object instance. We have therefore transferred a lot to the client/browser. We were able to achieve acceptable results with this. 

     

    Best regards


  2. 3 hours ago, hschmid67 said:

    Hello,

     

    I'm looking for something similar - implementing python scripts in webservice procedures. Were You able to find a solution for this and would You mind to share it?

     

    Regards

    Harald

    Hello Harald,

     

    Unfortunately, I have not yet found a way to implement this. 
    I think at the moment the only possibility would be, as I wrote at the time, to multiply the dlls and then load them several times so that you have an independent dll environment for each thread.  

    However, this would probably mean quite a lot of effort to rewrite this in the core libraries.

     

    Many greetings


  3. Additional question: 😀

     

    I did some performance tests and unfortunately came to the expected result that normal thread processing does not bring any significant performance benefits.

    For my test I used the Fibonacci algorithm to generate a high CPU load and a low IO load. 

     

    Are there ways, apart from additional processes, to improve the performance of parallel processing?

    I am talking here in the context of processing a wide variety of scripts or problems that cannot be parallelized themselves.

     

    Is there a possibility to use Python derivatives like CPython or IronPython without or with a disableableable GIL?

     

    From another area of resource sharing of dll libraries, a viable way was to duplicate the dll's and load them multiple times.

    Would this also be a possible approach here with Python and Delphi? 

     

    Best regards


  4. Hi,

     

    I have a problem running Python scripts in threads.

    The execution stucks in TPythonThread.Execute --> gilstate := PyGILState_Ensure(); and never return.

    Here is my example console application.

    program p4dtest;
    
    {$APPTYPE CONSOLE}
    {$R *.res}
    
    uses
      System.SysUtils,
      System.Classes,
    
      PythonEngine;
    
    type
      TMyPythonThread = class(TPythonThread)
      protected
        procedure ExecuteWithPython; override;
      public
        constructor Create;
      end;
    
      TMyServiceHelper = class
      public
        ThreadCount : Integer;
      public
        procedure ThreadDone(Sender: TObject);
      end;
    
    { TMyPythonThread }
    
    constructor TMyPythonThread.Create;
    begin
      Self.ThreadExecMode  := emNewInterpreter;
      Self.FreeOnTerminate := true;
    
      inherited Create(true);
    end;
    
    procedure TMyPythonThread.ExecuteWithPython;
    begin
      Writeln('Test1');
      GetPythonEngine.ExecString('print("Test2")');
    end;
    
    { TMyServiceHelper }
    
    procedure TMyServiceHelper.ThreadDone(Sender: TObject);
    begin
      Dec(ThreadCount);
    end;
    
    var
      MyPythonEngine  : TPythonEngine;
      MyPyInOut       : TMyPythonGUIInputOutput;
      MySvcHelper     : TMyServiceHelper;
      Threads         : Array of TMyPythonThread;
      i               : Integer;
    
    begin
      try
        MyPythonEngine := TPythonEngine.Create(nil);
        MySvcHelper    := TMyServiceHelper.Create;
        try
          MyPythonEngine.InitThreads := true;
          MyPythonEngine.LoadDll;
    
          MySvcHelper.ThreadCount := 1;
          SetLength(Threads,1);
          for i:=0 to 0 do
          begin
            Threads[i] := TMyPythonThread.Create;
            Threads[i].OnTerminate := MySvcHelper.ThreadDone;
            Threads[i].Start;
          end;
    
          repeat
            CheckSynchronize;
            sleep(10);
          until MySvcHelper.ThreadCount = 0;
    
          Writeln('Done');
          ReadLn;
        finally
          FreeAndNil(MyPythonEngine);
          FreeAndNil(MySvcHelper);
        end;
      except
        on E: Exception do
        begin
          Writeln(E.ClassName, ': ', E.Message);
          ReadLn;
        end;
      end;
    end.

     

    Any ideas?

    Best regards.


  5. Unfortunately now I get a "range check" exception here:

     

    [PythonEngine.pas / Line 4219]

    if Assigned(Py_SetProgramName) and (ProgramName <> '') then
        Py_SetProgramName(PWCharT(FProgramName));

     

    My "configuration" is:

    PythonEngine.UseLastKnownVersion := false;
    PythonEngine.DllPath := '/usr/lib/x86_64-linux-gnu';
    PythonEngine.DllName := 'libpython3.9.so.1.0';

     

    Any ideas?

    Best regards


  6. Hi,

     

    unfortunately it's not possible to compile PythonEngine.pas for Linux64 with Delphi 10.4.

     

    [DCC Fehler] PythonEngine.pas(198): E2003 Undeklarierter Bezeichner: 'PUCSChar'
    [DCC Fehler] PythonEngine.pas(199): E2007 Konstante oder Typenbezeichner erwartet
    [DCC Fehler] PythonEngine.pas(4396): E2010 Inkompatible Typen: 'Dynamic array' und 'UCS4String'

     

    Any ideas?

    Best regards

×