retrieving a return code from a thread

Discussion in 'Python' started by Jean-Yves Nief, Feb 8, 2004.

  1. hi all,

    I would like to know how I can retrieve in my main program the
    return code from a thread that I launched:
    class example(threading.Thread):

    def __init__(self, filename):
    self.filename = filename
    threading.Thread.__init__(self)
    self.start()

    def run(self):
    ........
    rc = os.system("command example")

    in the main thread:
    ......
    thrdExample = []
    thrdExample.append(example(file))
    ......
    # once it's not active anymore, test of the return code for
    thrdExample ??

    thanks in advance,
    JY
    Jean-Yves Nief, Feb 8, 2004
    #1
    1. Advertising

  2. You could use a synchronized Queue (look into the docs) where the running
    thread(s) put their results. The main loop waits until some or all results
    are there, and then continues processing.

    --
    Regards,

    Diez B. Roggisch
    Diez B. Roggisch, Feb 8, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wl
    Replies:
    2
    Views:
    582
    Dimitri Maziuk
    Mar 5, 2004
  2. JY
    Replies:
    0
    Views:
    291
  3. Greenhorn
    Replies:
    15
    Views:
    812
    Keith Thompson
    Mar 6, 2005
  4. Rajat

    thread return code

    Rajat, Jan 19, 2010, in forum: Python
    Replies:
    3
    Views:
    842
    Dennis Lee Bieber
    Jan 20, 2010
  5. Replies:
    1
    Views:
    160
    R. Rajesh Jeba Anbiah
    Jan 13, 2005
Loading...

Share This Page