File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change
1
+ trio-asyncio no longer raises a spurious "Event loop stopped before Future
2
+ completed!" exception if a function passed to :func: `asyncio.run ` calls
3
+ :func: `sys.exit `.
Original file line number Diff line number Diff line change @@ -193,3 +193,13 @@ def noop():
193
193
await trio_asyncio .aio_as_trio (loop .run_in_executor )(executor , noop )
194
194
195
195
assert not scope .cancelled_caught
196
+
197
+
198
+ def test_system_exit ():
199
+ async def main ():
200
+ raise SystemExit (42 )
201
+
202
+ with pytest .raises (SystemExit ) as scope :
203
+ asyncio .run (main ())
204
+
205
+ assert scope .value .code == 42
Original file line number Diff line number Diff line change @@ -139,6 +139,14 @@ def is_done(_):
139
139
nonlocal result
140
140
141
141
result = outcome .capture (future .result )
142
+ if isinstance (result , outcome .Error ) and isinstance (
143
+ result .error , (SystemExit , KeyboardInterrupt )
144
+ ):
145
+ # These exceptions propagate out of the event loop;
146
+ # don't stop the event loop again, or else it will
147
+ # interfere with cleanup actions like
148
+ # run_until_complete(shutdown_asyncgens)
149
+ return
142
150
self .stop ()
143
151
144
152
future .add_done_callback (is_done )
You can’t perform that action at this time.
0 commit comments