tags:

views:

761

answers:

3

I'm hosting Python script with Python for Delphi components inside my Delphi application. I'd like to create background tasks which keep running by script.

Is it possible to create threads which keep running even if the script execution ends (but not the host process, which keeps going on). I've noticed that the program gets stuck if the executing script ends and there is thread running. However if I'll wait until the thread is finished everything goes fine.

I'm trying to use "threading" standard module for threads.

A: 

Threads by definition are part of the same process. If you want them to keep running, they need to be forked off into a new process; see os.fork() and friends.

You'll probably want the new process to end (via exit() or the like) immediately after spawning the script.

pjz
The execution of script in host applications ends, but the process keeps going on.
Harriv
I think I need everything to work inside same process, but thank you for suggestion.
Harriv
A: 

If a process dies all it's threads die with it, so a solution might be a separate process.

See if creating a xmlrpc server might help you, that is a simple solution for interprocess communication.

Toni Ruža
+2  A: 

Python has its own threading module that comes standard, if it helps. You can create thread objects using the threading module.

threading Documentation

thread Documentation

The thread module offers low level threading and synchronization using simple Lock objects.

Again, not sure if this helps since you're using Python under a Delphi environment.

junkforce
Yes, I'm using those modules.
Harriv