Threading in python: retrieve return value when using target=

Posted by Philipp Keller on Stack Overflow See other posts from Stack Overflow or by Philipp Keller
Published on 2010-04-05T06:43:36Z Indexed on 2010/04/05 6:53 UTC
Read the original article Hit count: 367

Filed under:
|
|

I want to get the "free memory" of a bunch of servers like this:

def get_mem(servername):  
    res = os.popen('ssh %s "grep MemFree /proc/meminfo | sed \'s/[^0-9]//g\'"' % servername)  
    return res.read().strip()  

since this can be threaded I want to do something like that:

import threading  
thread1 = threading.Thread(target=get_mem, args=("server01", ))  
thread1.start()

But now: how can I access the return value(s) of the get_mem functions? Do I really need to go the full fledged way creating a class MemThread(threading.Thread) and overwriting __init__ and __run__?

© Stack Overflow or respective owner

Related posts about python

Related posts about threading