File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -692,6 +692,20 @@ mod sys {
692692 vm. use_tracing . set ( tracing) ;
693693 }
694694
695+ #[ pyfunction]
696+ fn set_coroutine_origin_tracking_depth ( depth : i32 , vm : & VirtualMachine ) -> PyResult < ( ) > {
697+ if depth < 0 {
698+ return Err ( vm. new_value_error ( "depth must be >= 0" . to_owned ( ) ) ) ;
699+ }
700+ crate :: vm:: thread:: COROUTINE_ORIGIN_TRACKING_DEPTH . with ( |cell| cell. set ( depth as _ ) ) ;
701+ Ok ( ( ) )
702+ }
703+
704+ #[ pyfunction]
705+ fn get_coroutine_origin_tracking_depth ( ) -> i32 {
706+ crate :: vm:: thread:: COROUTINE_ORIGIN_TRACKING_DEPTH . with ( |cell| cell. get ( ) ) as _
707+ }
708+
695709 /// sys.flags
696710 ///
697711 /// Flags provided through command line arguments or environment vars.
Original file line number Diff line number Diff line change 11use crate :: { AsObject , PyObject , VirtualMachine } ;
22use itertools:: Itertools ;
33use std:: {
4- cell:: RefCell ,
5- ptr:: { null , NonNull } ,
4+ cell:: { Cell , RefCell } ,
5+ ptr:: NonNull ,
66 thread_local,
77} ;
88
99thread_local ! {
1010 pub ( super ) static VM_STACK : RefCell <Vec <NonNull <VirtualMachine >>> = Vec :: with_capacity( 1 ) . into( ) ;
11- static VM_CURRENT : RefCell <* const VirtualMachine > = null:: <VirtualMachine >( ) . into( ) ;
11+ static VM_CURRENT : RefCell <* const VirtualMachine > = std:: ptr:: null:: <VirtualMachine >( ) . into( ) ;
12+
13+ pub ( crate ) static COROUTINE_ORIGIN_TRACKING_DEPTH : Cell <u32 > = Cell :: new( 0 ) ;
1214}
1315
1416pub fn with_current_vm < R > ( f : impl FnOnce ( & VirtualMachine ) -> R ) -> R {
@@ -142,7 +144,6 @@ impl VirtualMachine {
142144 /// specific guaranteed behavior.
143145 #[ cfg( feature = "threading" ) ]
144146 pub fn new_thread ( & self ) -> ThreadedVirtualMachine {
145- use std:: cell:: Cell ;
146147 let vm = VirtualMachine {
147148 builtins : self . builtins . clone ( ) ,
148149 sys_module : self . sys_module . clone ( ) ,
You can’t perform that action at this time.
0 commit comments