How can I achieve communication between threads?
I have one thread in which I do some stuff, then I need to call a method from an object that lives in the main program thread and this method should be executed in the main process:
class Foo():
def help(self):
pass
class MyThread(threading.Thread):
def __init__(self, connection, parser, queue=DEFAULT_QUEUE_NAME):
threading.Thread.__init__(self)
def run(self):
# do some work
# here I need to call method help() from Foo()
# but I need to call it in main process
bar = Foo()
my_work_thread = MyThread()
my_work_thread.run()
barin the separate thread is identical tobarin the main thread