freelanceprogrammers.org Forum Index » Delphi
Delayed startup
Joined: 06 Oct 2005
Posts: 7
Delayed startup
For various reasons I`m trying to update some python for delphi code
and am finding it hard to get the output.
The original code started its own python engine after form
initialisation (I think that`s so it can set up dll paths etc etc).
I dropped a memo and a TPythonGUIInputOutput onto my form and
connected output to the memo.
Now in my startup routine I have this code
setEnvironmentVariable(`PYTHONHOME`,pChar(appDir));
pyPath:= self.getPyPathFromDirs(pyDirs);
fEngine:= TMyAtomPythonEngine.Create(nil);
fEngine.io := pyIO; {IO set}
fEngine.dllPath:= appDir; // dir containing python dll
fEngine.pyFlags := [pfNoSite];
fEngine.RedirectIO:= True;
fEngine.loaded;
fEngine.execString(format(`import sys; sys.path[:] =
r"%s".split(";")`, [pyPath]));
// For debugging
fEngine.execString(`print "sys.path =", sys.path`);
fEngine.execString(`print "sys.modules = ", sys.modules`);
but although the app still behaves OK I don`t seem to see prints
coming out in my memo. Debugging reveals that pyIO is the right object
and the engine startup seems to do the right thing.
What am I missing?
Robin Becker
Joined: 06 Oct 2005
Posts: 7
Delayed startup
--- In pythonfordelphi@yahoogroups.com, "rg_becker" <robin@...> wrote:
.......
> but although the app still behaves OK I don`t seem to see prints
> coming out in my memo. Debugging reveals that pyIO is the right object
> and the engine startup seems to do the right thing.
>
> What am I missing?
... turns out this is a threading issue
Looking in PythonEngine.pas I see that the wrapped stdout/stderr are
not serviced if the current thread is not the main one. A discussion
earlier mentioned this and that a possible solution involved a
separate window to handle a message posting fix. Some of that seems to
be in place now.
It seems that if I use PythonGUIInputOutput with the code in pio_write
modified to avoid the current thread return
ie
if False and (GetCurrentThreadId <> MainThreadId) then
and fix
procedure TPythonInputOutput.AddWrite( const str : String );
begin
FQueue.Add( str );
if FQueue.Count > FMaxLines then
FQueue.Delete(0);
AddPendingWrite;
end;
then I can get the threading test in Demo11 to do lots of output from
Threads 1 2 and 3. Makes the test a bit slower, but I get no problems.
Interestingly if I use delaywrites:=True then I do get a problem in
the message handling.
Robin
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







