def notifyOnExit(self, processHandle, processTransport):
processHandleKey = self.phandleToPhandleKey[processHandle]
# If there are available threads, use one of them
if len(self.availableThreads) > 0:
wfmoThread = self.availableThreads[0]
self.threadToNumProcessHandles[wfmoThread] += 1
self.phandleKeyToThreadHandle[processHandleKey] = wfmoThread
# Update used/available thread lists
if self.threadToNumProcessHandles[wfmoThread] == 63:
self.usedThreads.append(wfmoThread)
self.availableThreads.remove(wfmoThread)
# Make sure the message window has been created so
# we can send messages to the thread.
if self.threadToMsgWindowCreated[wfmoThread] is False:
val = WaitForSingleObject(self.threadToMsgWindowCreationEvent[wfmoThread], INFINITE)
if val != WAIT_OBJECT_0:
raise RuntimeError("WaitForSingleObject returned %d. It should only return %d" % (val, WAIT_OBJECT_0))
# Notify the thread that it should wait on the process handle.
if win32api.PostMessage(
self.threadToMsgWindow[wfmoThread],
WM_NEW_PHANDLE, # message
processHandleKey, # wParam
0 # lParam
) == 0:
raise Exception("Failed to post thread message!")
else:
# Create a new thread and wait on the proc handle
wfmoThread = threading.Thread(
target=self.doWaitForProcessExit,
args=(processHandleKey,),
name="iocpreactor.process_waiter.ProcessWaiter.waitForProcessExit pid=%d" % self.realPid)
# Create a window creation event that will be triggered from the thread
self.threadToMsgWindowCreationEvent[wfmoThread] = CreateEvent(None, 0, 0, None)
self.threadToMsgWindowCreated[wfmoThread] = False
self.threadToNumProcessHandles[wfmoThread] = 1
self.availableThreads.append(wfmoThread)
self.phandleKeyToThreadHandle[processHandleKey] = wfmoThread
wfmoThread.start()
评论列表
文章目录