Comments (8)
Please see https://github.com/pyscripter/python4delphi/wiki/PythonThreads
from python4delphi.
Unfortunately, nothing works. None of the methods given in the article. There is simply no response. I have logging, but nothing is written in the log.
What am I doing wrong? Python embedded version is 3.8. Delphi 11.3
Here is my code:
ThreadPythonExec(
procedure
begin
GetPythonEngine.ExecFile(PyFileName);
end{, nil, false, emNewInterpreter});
Task := TTask.Create(
procedure
var
Py: IPyEngineAndGIL;
begin
Py := SafePyEngine;
Py.PythonEngine.ExecFile(PyFileName);
end);
Task.Start;
from python4delphi.
Are you doing this?
You should call Py_Begin_Allow_Threads in your main thread, after the python DLL was loaded, for example in your FormCreate event handler.
Also have a look at Demo 33.
from python4delphi.
Thanks for the help, it really worked. But the problem hasn't completely disappeared.
I call TPythonThread.Py_Begin_Allow_Threads when I create a form. I also call TPythonThread.Py_End_Allow_Threads when closing the form. Everything is fine, everything works fine. But if I close the form and start the form again, then there is a problem in the script with the numpy module again(other packages seem to be fine). I get an error:
C:\A\34\s/Objects/structsseq.c:398: bad argument to internal function
When I close the form, I unload the dll:
procedure TfrmScripts.FormDestroy(Sender: TObject);
begin
PyEngine.UnloadDll;
TPythonThread.Py_End_Allow_Threads; // Acquire the GIL
FreeAndNil(PyEngine);
inherited;
end;
What am I doing wrong?
from python4delphi.
Why do you free the engine?
Destroying and recreating the engine is not a good idea.
from python4delphi.
I create PythonEngine dynamically on form create. But it doesn't make any difference. Even if I use TPythonEngine component (put ting it on a form, so I don't need destroy it on closing form), still this error occurs. I have an MDI application. What do you recommend?
Put TPythonEngine component in Data Module?
Destroying and recreating the engine is not a good idea.
Why?
from python4delphi.
It makes no difference if you put the PythonEngine on a Form or a DataModule. Are you releasing the GIL before running python code again?
I am not sure what causes the error in your program, but this is not a P4D issue. You may get some help if you use the Support forum.
from python4delphi.
Are you releasing the GIL before running python code again?
on form create:
TPythonThread.Py_Begin_Allow_Threads;
on form destroy:
TPythonThread.Py_End_Allow_Threads;
from python4delphi.
Related Issues (20)
- Running Demos from Delphi-12 HOT 1
- Pagecontrol.ActivePage wrapper function causes AV error HOT 8
- "demo33 -- three interpreter" causes the thread to hang. HOT 7
- floating point division by zero HOT 1
- python dll HOT 1
- VarPyIterate raises EPyStopIteration exception with message 'Stop Iteration' HOT 2
- Running python code in Delphi threads issue HOT 1
- Pyhton4Delphi and streamlit HOT 3
- How to specify the path to Python libraries? HOT 4
- Run the .py file immediately with parameters HOT 8
- How can I output the results of a py script? HOT 9
- OnSendUniData event does not work HOT 4
- Wrongly throwing an exception from the wrapping object HOT 2
- A little problem HOT 2
- Error in ExtractPythonObjectFrom when creating Enum? HOT 1
- [dcc64 fatal error] PythonVcl.dpk: F2084 Internal Error on RAD Studio 12.1 HOT 6
- Minor: Typo in error message
- Pandas with Python 3.12 HOT 12
- using python4delphi via compiled DLL, avoids reading variables from python to delphi HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python4delphi.