-
-
Notifications
You must be signed in to change notification settings - Fork 324
Using the library in a Windows service. Is that possible ? #487
-
If I try to create an instance of TPythonEngine in a 64 bit Windows service, if the AutoLoad property is set to True the service does not start.
If the AutoLoad property is set to False the service starts bat as soon as I call the method LoadDll the service hangs and I have to kill it from Task Manager.
The question is : is this library compatible with Windows services ?
Beta Was this translation helpful? Give feedback.
All reactions
When you run as a service the registry information is not available. You need to do something like:
procedure TService1.CreatePyEngine;
begin
PythonEngine := TPythonEngine.Create(nil);
PythonEngine.Name := 'PythonEngine';
PythonEngine.DLLName := 'python313.dll';
PythonEngine.DllPath := 'c:\pathtoyourpythonhome';
PythoneEngine.PythonHome := PythonEngine.DLLPath;
PythonEngine.RegVersion := '3.13';
PythonEngine.UseLastKnownVersion := False;
PythonEngine.FatalAbort := False;
PythonEngine.FatalMsgDlg := False;
PythonEngine.LoadDll;
end;
I have tested and it works.
Replies: 2 comments 1 reply
-
The question is : is this library compatible with Windows services ?
I don't know. But I don't see why not.
However AutoLoad is relevant when using visual components in a form. You will have to create the components and load the dll manually.
Have you got a recent python installed?
Can you debug and see what happens when you call LoadDLL?
Also have you read https://github.com/pyscripter/python4delphi/wiki/FindingPython?
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you for your replay.
I have Python installed and registered on my machine and I normally leave UseLastKnownVerion = True and everything works as expected (in VCL GUI applications and console applications).
I normally write code in console mode for easy testing and debug and than I compile exactly the same code as a Windows service.
In console mode everything works fine, but when I compile as a Windows service I get the problem I already described.
The issue is very easy to reproduce with these steps:
- Create a brand new TService application
- Drop on the TService module a TPythonEngine component
- Save and compile
- Register the service
- Lauch the service from Services: after a while you get "Windows could not start the #SERVICENAME# service on local computer...."
- Deselect "AutLoad" on the pythonEngine component and compile again.
- Lauch the service from Services and the service starts as expected.
Beta Was this translation helpful? Give feedback.
All reactions
-
When you run as a service the registry information is not available. You need to do something like:
procedure TService1.CreatePyEngine;
begin
PythonEngine := TPythonEngine.Create(nil);
PythonEngine.Name := 'PythonEngine';
PythonEngine.DLLName := 'python313.dll';
PythonEngine.DllPath := 'c:\pathtoyourpythonhome';
PythoneEngine.PythonHome := PythonEngine.DLLPath;
PythonEngine.RegVersion := '3.13';
PythonEngine.UseLastKnownVersion := False;
PythonEngine.FatalAbort := False;
PythonEngine.FatalMsgDlg := False;
PythonEngine.LoadDll;
end;
I have tested and it works.
Beta Was this translation helpful? Give feedback.