July 29th, 2005, 06: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, 09: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, 11:55 AM
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, 12: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!
July 31st, 2005, 11:10 PM
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?