Skip to content

Commit 37f0baf

Browse files
committed
fix process hanging due to reactor.stop() being called twice on sigint
1 parent 5dc4efc commit 37f0baf

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pytest_twisted.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,15 @@ def init_twisted_greenlet():
208208

209209
def stop_twisted_greenlet():
210210
if _instances.gr_twisted:
211-
_instances.reactor.stop()
211+
# check if the reactor is not stopped first to prevent calling stop() twice which results
212+
# into an error, traceback printed and process hanging until it is killed with SIGKILL.
213+
# This sometimes happens when the pytest process is sent a SIGINT signal.
214+
# The reactor will stop itself as it register a SIGINT signal for itself and then it is
215+
# stopped second time here.
216+
# I don't understand when exactly is this happening but I am also observing here that
217+
# reactor.running == True and reactor._stopped == True.
218+
if not _instances.reactor._stopped:
219+
_instances.reactor.stop()
212220
_instances.gr_twisted.switch()
213221

214222

0 commit comments

Comments
 (0)