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. Advertisements

  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. Advertisements

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. Charles A. Lackman

    Terminating a thread from the main thread

    Charles A. Lackman, Dec 9, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,760
    Herfried K. Wagner [MVP]
    Dec 9, 2004
  2. niju
    Replies:
    6
    Views:
    9,856
  3. wl
    Replies:
    2
    Views:
    743
    Dimitri Maziuk
    Mar 5, 2004
  4. JY
    Replies:
    0
    Views:
    351
  5. Greenhorn
    Replies:
    15
    Views:
    1,115
    Keith Thompson
    Mar 6, 2005
  6. Rajat

    thread return code

    Rajat, Jan 19, 2010, in forum: Python
    Replies:
    3
    Views:
    1,049
    Dennis Lee Bieber
    Jan 20, 2010
  7. Ryan
    Replies:
    3
    Views:
    231
  8. Replies:
    1
    Views:
    269
    R. Rajesh Jeba Anbiah
    Jan 13, 2005
Loading...