threading - how to get parent id/name?
Make a Thread subclass that sets a parent
attribute on init:
from threading import current_thread
class MyThread(threading.Thread):
def __init__(self, *args, **kwargs):
self.parent = current_thread()
Thread.__init__(self, *args, **kwargs)
Then, while doing work inside a thread started with this class, we can access current_thread().parent
to get the spawning Thread object.