Threading in python: retrieve return value when using target=
- by Philipp Keller
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__?