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

    Join Date
    Aug 2013
    Posts
    1
    Rep Power
    0

    Spawn 2 python scripts at same time in windows


    Hi All,

    I have 2 python scripts and successfully executes when run in sequential, but i am looking to have 1 master script which will execute 2 scripts at the same time, gather results from 2 scripts into a master script.

    Could some one please help me to achieve this?

    Regards,
    Raj
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    153
    Rep Power
    5
    What you're describing is a multi-threaded application , in which you will be launching two scripts in their own threads and then retreiving the results asynchronously. I don't do a lot of this kind of programming, but the place you want to start reading is here:

    http://docs.python.org/2/library/threading.html

    Your "master" script is going to have to create two threads, start them, and then wait for each to complete.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    multi-processing is another way to go.

    I'd write a shell script to launch the programs or submit them to the batch queue. In unix,

    python p1.py &
    python p2.py &


    In DOS, (except that you'd need to look up the command) but effectively,

    start /nowait python p1.py
    start /nowait python p2.py
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo