Skip to content

Commit e3dcce2

Browse files
committed
os_fork: do not attempt to cork the active thread.
1 parent 3231c62 commit e3dcce2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

mitogen/os_fork.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import os
3636
import socket
3737
import sys
38+
import threading
3839
import weakref
3940

4041
import mitogen.core
@@ -157,19 +158,22 @@ def cork(self):
157158
held. This will not return until each thread acknowledges it has ceased
158159
execution.
159160
"""
161+
current = threading.currentThread()
160162
s = mitogen.core.b('CORK') * ((128 // 4) * 1024)
161163
self._rsocks = []
162164

163165
# Pools must be paused first, as existing work may require the
164166
# participation of a broker in order to complete.
165167
for pool in self.pools:
166168
if not pool.closed:
167-
for x in range(pool.size):
168-
self._cork_one(s, pool)
169+
for th in pool._threads:
170+
if th != current:
171+
self._cork_one(s, pool)
169172

170173
for broker in self.brokers:
171174
if broker._alive:
172-
self._cork_one(s, broker)
175+
if broker._thread != current:
176+
self._cork_one(s, broker)
173177

174178
# Pause until we can detect every thread has entered write().
175179
for rsock in self._rsocks:

0 commit comments

Comments
 (0)