File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
python/monarch/_src/actor Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -342,7 +342,7 @@ impl Actor for PythonActor {
342
342
/// Create a new TaskLocals with its own asyncio event loop in a dedicated thread.
343
343
fn create_task_locals ( ) -> pyo3_async_runtimes:: TaskLocals {
344
344
let ( tx, rx) = std:: sync:: mpsc:: channel ( ) ;
345
- let _ = std:: thread:: spawn ( move || {
345
+ let _ = std:: thread:: Builder :: new ( ) . name ( "asyncio-event-loop" . to_string ( ) ) . spawn ( move || {
346
346
Python :: with_gil ( |py| {
347
347
let asyncio = Python :: import ( py, "asyncio" ) . unwrap ( ) ;
348
348
let event_loop = asyncio. call_method0 ( "new_event_loop" ) . unwrap ( ) ;
@@ -354,7 +354,19 @@ fn create_task_locals() -> pyo3_async_runtimes::TaskLocals {
354
354
. copy_context ( py)
355
355
. unwrap ( ) ;
356
356
tx. send ( task_locals) . unwrap ( ) ;
357
- event_loop. call_method0 ( "run_forever" ) . unwrap ( ) ;
357
+ // The event loop can surface an error if one of the tasks it runs raises
358
+ // an exception.
359
+ event_loop. call_method0 ( "run_forever" ) . inspect_err ( |err| {
360
+ eprintln ! ( "Event loop exited with error: {}" , err) ;
361
+ } ) ;
362
+ // Regardless of whether the event loop exited cleanly or not, we need
363
+ // to close the loop. Equivalent to finally in Python.
364
+ event_loop. call_method0 ( "stop" ) . inspect_err ( |err| {
365
+ eprintln ! ( "Failed to stop event loop: {}" , err) ;
366
+ } ) ;
367
+ event_loop. call_method0 ( "close" ) . inspect_err ( |err| {
368
+ eprintln ! ( "Failed to close event loop: {}" , err) ;
369
+ } ) ;
358
370
} ) ;
359
371
} ) ;
360
372
rx. recv ( ) . unwrap ( )
Original file line number Diff line number Diff line change @@ -807,6 +807,10 @@ async def instrumented():
807
807
port .exception (ActorError (e ))
808
808
except BaseException as e :
809
809
self ._post_mortem_debug (e .__traceback__ )
810
+ if isinstance (e , SystemExit ):
811
+ # SystemExit is a BaseException but not a rust panic. We'll just
812
+ # reraise it
813
+ raise
810
814
# A BaseException can be thrown in the case of a Rust panic.
811
815
# In this case, we need a way to signal the panic to the Rust side.
812
816
# See [Panics in async endpoints]
You can’t perform that action at this time.
0 commit comments