1
1
"""
2
2
base execnet gateway code send to the other side for bootstrapping.
3
3
4
- NOTE: aims to be compatible to Python 2.5-3.X, Jython and IronPython
4
+ NOTE: aims to be compatible to Python 3.8+
5
5
6
6
:copyright: 2004-2015
7
7
:authors:
@@ -153,6 +153,8 @@ class Reply:
153
153
through WorkerPool.spawn()
154
154
"""
155
155
156
+ _exception : BaseException | None = None
157
+
156
158
def __init__ (self , task , threadmodel ):
157
159
self .task = task
158
160
self ._result_ready = threadmodel .Event ()
@@ -165,10 +167,10 @@ def get(self, timeout=None):
165
167
including its traceback.
166
168
"""
167
169
self .waitfinish (timeout )
168
- try :
170
+ if self . _exception is None :
169
171
return self ._result
170
- except AttributeError :
171
- reraise ( * ( self ._excinfo [: 3 ])) # noqa
172
+ else :
173
+ raise self . _exception . with_traceback ( self ._exception . __traceback__ )
172
174
173
175
def waitfinish (self , timeout = None ):
174
176
if not self ._result_ready .wait (timeout ):
@@ -179,10 +181,9 @@ def run(self):
179
181
try :
180
182
try :
181
183
self ._result = func (* args , ** kwargs )
182
- except :
184
+ except BaseException as e :
183
185
# sys may be already None when shutting down the interpreter
184
- if sys is not None :
185
- self ._excinfo = sys .exc_info ()
186
+ self ._exception = e
186
187
finally :
187
188
self ._result_ready .set ()
188
189
self .running = False
@@ -348,7 +349,9 @@ def __init__(self, outfile, infile, execmodel):
348
349
except (AttributeError , OSError ):
349
350
pass
350
351
self ._read = getattr (infile , "buffer" , infile ).read
351
- self ._write = getattr (outfile , "buffer" , outfile ).write
352
+ _outfile = getattr (outfile , "buffer" , outfile )
353
+ self ._write = _outfile .write
354
+ self ._flush = _outfile .flush
352
355
self .execmodel = execmodel
353
356
354
357
def read (self , numbytes ):
@@ -366,7 +369,7 @@ def write(self, data):
366
369
"""write out all data bytes."""
367
370
assert isinstance (data , bytes )
368
371
self ._write (data )
369
- self .outfile . flush ()
372
+ self ._flush ()
370
373
371
374
def close_read (self ):
372
375
self .infile .close ()
0 commit comments