#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    7
    Rep Power
    0

    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...
    thanks
    Francesco
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    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 .

    http://python.org/doc/2.2.3/lib/os-process.html

    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    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".

    Dave

    Comments on this post

    • netytan agrees : Now why didn't I think of that ;). Thanks Dave.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Posts
    7
    Rep Power
    0
    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!
    Ciao
    Francesco
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Questioner's home
    Posts
    89
    Rep Power
    12
    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?

IMN logo majestic logo threadwatch logo seochat tools logo