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 {
692
692
vm. use_tracing . set ( tracing) ;
693
693
}
694
694
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
+
695
709
/// sys.flags
696
710
///
697
711
/// Flags provided through command line arguments or environment vars.
Original file line number Diff line number Diff line change 1
1
use crate :: { AsObject , PyObject , VirtualMachine } ;
2
2
use itertools:: Itertools ;
3
3
use std:: {
4
- cell:: RefCell ,
5
- ptr:: { null , NonNull } ,
4
+ cell:: { Cell , RefCell } ,
5
+ ptr:: NonNull ,
6
6
thread_local,
7
7
} ;
8
8
9
9
thread_local ! {
10
10
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 > = const { Cell :: new( 0 ) } ;
12
14
}
13
15
14
16
pub fn with_current_vm < R > ( f : impl FnOnce ( & VirtualMachine ) -> R ) -> R {
@@ -142,7 +144,6 @@ impl VirtualMachine {
142
144
/// specific guaranteed behavior.
143
145
#[ cfg( feature = "threading" ) ]
144
146
pub fn new_thread ( & self ) -> ThreadedVirtualMachine {
145
- use std:: cell:: Cell ;
146
147
let vm = VirtualMachine {
147
148
builtins : self . builtins . clone ( ) ,
148
149
sys_module : self . sys_module . clone ( ) ,
You can’t perform that action at this time.
0 commit comments