def _patch_main_thread(mod): # this is some gnarly patching for the threading module; # if threading is imported before we patch (it nearly always is), # then the main thread will have the wrong key in therading._active, # so, we try and replace that key with the correct one here # this works best if there are no other threads besides the main one curthread = mod._active.pop(mod._get_ident(), None) if curthread: mod._active[thread.get_ident()] = curthread
def run(self): self.id = thread.get_ident() self.finished = False try: while True: worker_started.set() time.sleep(0.1) except AsyncExc: self.finished = True worker_saw_exception.set()