July 29th, 2005, 07:27 AM
make loop go to a separate process
Hello, is it possible to have a loop go into a separate process?
Otherwise my application is stuck until the loop finishes and I cannot even step in the loop to break it by a user input...
July 29th, 2005, 10:11 AM
Its certainly possible, if not with os.system() etc then definitely with the newer subprocess module. That said os.spawn*() or os.fork() may be what you're looking for .
Both of these run a command in a separate process and return a PID. The down side is that they are best used on *nix so you're loosing portability by using them, that said this isn't a problem in most cases .
Hope this helps,
July 29th, 2005, 12:55 PM
It sounds like what you really are talking about is threads. Python has two modules for this, 'thread' and 'threading'.
Google for "python threading tutorial".
Comments on this post
July 29th, 2005, 01:22 PM
Thank you everyone, Dave had it right, I was looking into threads just now... fork and spawn is for other executables... that works quite well, but I have all in python code in one single program, so threads will be my daily bread for a while!
August 1st, 2005, 12:10 AM
Can someone kind enough to post a simple example on how to use threading? I tried to read some tutorial but the examples they used're too complicated for me...
Thanks in advance.
What can change the nature of a man?