

Celebr0
Members-
Content Count
38 -
Joined
-
Last visited
Everything posted by Celebr0
-
How to run one .py script in several instances at the same time ?
Celebr0 replied to Celebr0's topic in Python4Delphi
If I run 10 instances of my own program, then all 10 instances work, and if I create and then destroy pythonengine, it will write an error that the python .dll is already in use ? -
Hello, I ran into a problem that input/output does not work through the OnReceiveUniData/OnReceiveData event and others, but it works through TPythonGUIInputOutput.Output unit Unit2; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, PythonEngine, PythonGUIInputOutput; type TForm2 = class(TForm) Button1: TButton; Button2: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure OnReceiveUniData(Sender: TObject; var Data: string); procedure CreatePyEngine; private { Private declarations } public { Public declarations } end; var Form2: TForm2; PythonEngine: TPythonEngine; working: boolean = True; implementation {$R *.dfm} procedure TForm2.OnReceiveUniData(Sender: TObject; var Data: string); begin Memo1.Lines.Add(Data); //No Memo1.Lines.Add('2'); //No end; procedure TForm2.CreatePyEngine; var pyio:TPythonGUIInputOutput; begin pyio := TPythonGUIInputOutput.Create(nil); pyio.UnicodeIO := True; pyio.DelayWrites := True; pyio.OnReceiveUniData := OnReceiveUniData; //pyio.Output:=Memo1; //------- WORK PythonEngine := TPythonEngine.Create(nil); PythonEngine.IO := pyio; PythonEngine.RedirectIO := True; PythonEngine.LoadDll; TPythonThread.Py_Begin_Allow_Threads; end; procedure TForm2.Button1Click(Sender: TObject); const Script ='print("Hello")'; begin CreatePyEngine; // TThread.CreateAnonymousThread( procedure var Py: IPyEngineAndGIL; begin Py := SafePyEngine; while working do PythonEngine.ExecString(Script); end).Start; end; procedure TForm2.Button2Click(Sender: TObject); begin working:=False; end; end.
-
Big Thanks This Is Work: procedure TForm2.OnData(Sender: TObject; const Data: string); begin Memo1.Lines.Add(Data); end; procedure TForm2.CreatePyEngine; var pyio:TPythonInputOutput; begin pyio := TPythonInputOutput.Create(nil); pyio.UnicodeIO := True; pyio.DelayWrites := False; pyio.OnSendUniData := OnData; PythonEngine := TPythonEngine.Create(nil); PythonEngine.IO := pyio; PythonEngine.RedirectIO := True; PythonEngine.LoadDll; TPythonThread.Py_Begin_Allow_Threads; end;
-
Hi of course I can py4delph.zip
-
Too Not work procedure TForm2.OnData(Sender: TObject; const Data: string); begin Memo1.Lines.Add(Data); //No Memo1.Lines.Add('2'); //No end; procedure TForm2.CreatePyEngine; var pyio:TPythonInputOutput; begin pyio := TPythonInputOutput.Create(nil); pyio.UnicodeIO := True; pyio.DelayWrites := True; pyio.OnSendUniData := OnData; //pyio.Output:=Memo1; //------- WORK PythonEngine := TPythonEngine.Create(nil); PythonEngine.IO := pyio; PythonEngine.RedirectIO := True; PythonEngine.LoadDll; TPythonThread.Py_Begin_Allow_Threads; end;
-
Hello, it still doesn't work =( procedure TForm2.CreatePyEngine; var pyio:TPythonInputOutput; begin pyio := TPythonInputOutput.Create(nil); pyio.UnicodeIO := True; pyio.DelayWrites := True; pyio.OnReceiveUniData := OnReceiveUniData; //pyio.Output:=Memo1; //------- WORK PythonEngine := TPythonEngine.Create(nil); PythonEngine.IO := pyio; PythonEngine.RedirectIO := True; PythonEngine.LoadDll; TPythonThread.Py_Begin_Allow_Threads; end;
-
Hello, please tell me, I need to run one .py script, but every time in a new window, and by default it runs in one: procedure ExecPythonFile(const MyPyFile:String); var Py: IPyEngineAndGIL; begin Py := SafePyEngine; try Py.PythonEngine.ExecFile(MyPyFile); except end; end; Due to the fact that the script runs in only one window, my small program crashes even on 10 threads =(
-
Hello again, in new versions of Python, they accelerated the GIL in python4delphi, is it emNewInterpreterOwnGIL? I just noticed that emNewInterpreterOwnGIL does not work with .py files ?
-
I just can't run 10 instances of a .py script through Python4Delphi, right? - There must be a bad low-quality library (
-
Hello, look what I need to achieve, I can run one .py script in at least 10 console windows at the same time, but I can’t achieve this through Python4Delphi with GIL locking only one running .py script works at a time
-
Does my code look exactly like this or differently?
-
Dude, all the indentations are correct everywhere, I don’t know where you got the idea that they are incorrect?
-
Perhaps I asked the question a little incorrectly, here's how I do it: type TPyThread = class(TPythonThread) protected procedure ExecuteWithPython; override; public constructor Сreate(createsuspended: boolean); end; procedure ExecPythonFile(const FFile, Params:string); const Arg: string = 'import sys' + #10 + 'def run_python_script(args_str):'+#10+ ' args_list = args_str.split()'+#10+ ' sys.argv = [sys.argv[0]] + args_list'; var Py: IPyEngineAndGIL; begin try PythonEngine.ExecString(Arg+#10+'run_python_script("'+Params+'")'); PythonEngine.ExecFile(FFile); finally end; end; constructor TPyThread.Сreate(createsuspended: boolean); begin inherited Create(CreateSuspended); ThreadExecMode:=emNewInterpreterOwnGIL; // I USE Python12.dll FreeOnTerminate:=True; end; procedure TPyThread.ExecuteWithPython; while true do ExecPythonFile(myfilename,'-i 2000 --r'); end; My software just crashes after a while, please help In one thread it works fine, but at 10 the software crashes