File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -32,16 +32,28 @@ async def run_as_daemon(func, *args):
32
32
future = Future ()
33
33
future .set_running_or_notify_cancel ()
34
34
35
+ # A bug in python 3.7 makes it a bad idea to set a BaseException
36
+ # in a wrapped future (see except statement in asyncio.Task.__wakeup)
37
+ # Instead, we'll wrap base exceptions into exceptions and unwrap them
38
+ # on the other side of the call.
39
+ class BaseExceptionWrapper (Exception ):
40
+ pass
41
+
35
42
def daemon ():
36
43
try :
37
44
result = func (* args )
38
- except BaseException as e :
45
+ except Exception as e :
39
46
future .set_exception (e )
47
+ except BaseException as e :
48
+ future .set_exception (BaseExceptionWrapper (e ))
40
49
else :
41
50
future .set_result (result )
42
51
43
52
Thread (target = daemon , daemon = True ).start ()
44
- return await asyncio .wrap_future (future )
53
+ try :
54
+ return await asyncio .wrap_future (future )
55
+ except BaseExceptionWrapper as exc :
56
+ raise exc .args [0 ]
45
57
46
58
47
59
def protect_standard_streams (stream ):
You can’t perform that action at this time.
0 commit comments