@@ -20,7 +20,10 @@ pub(crate) mod _thread {
2020
2121 use crate :: {
2222 AsObject , Py , PyPayload , PyRef , PyResult , VirtualMachine ,
23- builtins:: { PyDictRef , PyIntRef , PyStr , PyTupleRef , PyType , PyTypeRef , PyUtf8StrRef } ,
23+ builtins:: {
24+ PyBaseExceptionRef , PyDictRef , PyIntRef , PyStr , PyTupleRef , PyType , PyTypeRef ,
25+ PyUtf8StrRef ,
26+ } ,
2427 common:: wtf8:: Wtf8Buf ,
2528 frame:: FrameRef ,
2629 function:: { ArgCallable , FuncArgs , KwArgs , OptionalArg , PySetterValue , TimeoutSeconds } ,
@@ -558,6 +561,19 @@ pub(crate) mod _thread {
558561 . map_err ( |_err| vm. new_runtime_error ( "can't start new thread" ) )
559562 }
560563
564+ fn report_unraisable_thread_exception (
565+ exc : PyBaseExceptionRef ,
566+ func : & ArgCallable ,
567+ vm : & VirtualMachine ,
568+ ) {
569+ let msg = func
570+ . as_ref ( )
571+ . repr ( vm)
572+ . ok ( )
573+ . map ( |repr| format ! ( "Exception ignored in thread started by {}" , repr. as_wtf8( ) ) ) ;
574+ vm. run_unraisable ( exc, msg, vm. ctx . none ( ) ) ;
575+ }
576+
561577 fn run_thread ( func : ArgCallable , args : FuncArgs , vm : & VirtualMachine ) {
562578 // Increment thread count when thread actually starts executing
563579 vm. state . thread_count . fetch_add ( 1 ) ;
@@ -572,11 +588,7 @@ pub(crate) mod _thread {
572588 if let Err ( exc) = func. invoke ( args, vm)
573589 && !exc. fast_isinstance ( vm. ctx . exceptions . system_exit )
574590 {
575- vm. run_unraisable (
576- exc,
577- Some ( "Exception ignored in thread started by" . to_owned ( ) ) ,
578- func. into ( ) ,
579- ) ;
591+ report_unraisable_thread_exception ( exc, & func, vm) ;
580592 }
581593 }
582594 for lock in SENTINELS . take ( ) {
@@ -1755,11 +1767,7 @@ pub(crate) mod _thread {
17551767 if let Err ( exc) = func. invoke ( ( ) , vm)
17561768 && !exc. fast_isinstance ( vm. ctx . exceptions . system_exit )
17571769 {
1758- vm. run_unraisable (
1759- exc,
1760- Some ( "Exception ignored in thread started by" . to_owned ( ) ) ,
1761- func. into ( ) ,
1762- ) ;
1770+ report_unraisable_thread_exception ( exc, & func, vm) ;
17631771 }
17641772 }
17651773 } ) )
0 commit comments