File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -3136,10 +3136,21 @@ def _on_broker_exit(self):
3136
3136
if not self .config ['profiling' ]:
3137
3137
os .kill (os .getpid (), signal .SIGTERM )
3138
3138
3139
+ #: On Python >3.4, the global importer lock has been sharded into a
3140
+ #: per-module lock, meaning there is no guarantee the import statement in
3141
+ #: service_stub_main will be truly complete before a second thread
3142
+ #: attempting the same import will see a partially initialized module.
3143
+ #: Sigh. Therefore serialize execution of the stub itself.
3144
+ service_stub_lock = threading .Lock ()
3145
+
3139
3146
def _service_stub_main (self , msg ):
3140
- import mitogen .service
3141
- pool = mitogen .service .get_or_create_pool (router = self .router )
3142
- pool ._receiver ._on_receive (msg )
3147
+ self .service_stub_lock .acquire ()
3148
+ try :
3149
+ import mitogen .service
3150
+ pool = mitogen .service .get_or_create_pool (router = self .router )
3151
+ pool ._receiver ._on_receive (msg )
3152
+ finally :
3153
+ self .service_stub_lock .release ()
3143
3154
3144
3155
def _on_call_service_msg (self , msg ):
3145
3156
"""
Original file line number Diff line number Diff line change @@ -98,6 +98,7 @@ def on_fork():
98
98
fixup_prngs ()
99
99
mitogen .core .Latch ._on_fork ()
100
100
mitogen .core .Side ._on_fork ()
101
+ mitogen .core .ExternalContext .service_stub_lock = threading .Lock ()
101
102
102
103
mitogen__service = sys .modules .get ('mitogen.service' )
103
104
if mitogen__service :
You can’t perform that action at this time.
0 commit comments