Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Using the library in a Windows service. Is that possible ?#487

Answeredbypyscripter
lucapretti asked this question inQ&A
Discussion options

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 ?

You must be logged in to vote

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

Comment options

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 readhttps://github.com/pyscripter/python4delphi/wiki/FindingPython?

You must be logged in to vote
1 reply
@lucapretti
Comment options

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:

  1. Create a brand new TService application
  2. Drop on the TService module a TPythonEngine component
  3. Save and compile
  4. Register the service
  5. Lauch the service from Services: after a while you get "Windows could not start the #SERVICENAME# service on local computer...."
  6. Deselect "AutLoad" on the pythonEngine component and compile again.
  7. Lauch the service from Services and the service starts as expected.
Comment options

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.

You must be logged in to vote
0 replies
Answer selected bypyscripter
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@lucapretti@pyscripter

[8]ページ先頭

©2009-2025 Movatter.jp