File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1313import  sysconfig 
1414import  tempfile 
1515import  textwrap 
16+ import  threading 
17+ import  time 
1618import  unittest 
1719import  warnings 
1820
2224from  test .support  import  script_helper 
2325from  test .support  import  socket_helper 
2426from  test .support  import  warnings_helper 
27+ from  test .support .os_helper  import  EnvironmentVarGuard 
2528
2629TESTFN  =  os_helper .TESTFN 
2730
@@ -794,6 +797,27 @@ def test_linked_to_musl(self):
794797            for  v  in  linked :
795798                self .assertIsInstance (v , int )
796799
800+     def  test_threadsafe_environmentvarguard (self ):
801+         def  worker1 (guard ):
802+             for  i  in  range (1000 ):
803+                 guard ['MY_VAR' ] =  'value1' 
804+                 time .sleep (0.0001 )  # Small delay to increase chance of thread switching 
805+ 
806+         def  worker2 (guard ):
807+             for  i  in  range (1000 ):
808+                 guard ['MY_VAR' ] =  'value2' 
809+                 time .sleep (0.0001 )
810+ 
811+         guard  =  EnvironmentVarGuard ()
812+         t1  =  threading .Thread (target = worker1 , args = (guard ,))
813+         t2  =  threading .Thread (target = worker2 , args = (guard ,))
814+         t1 .start ()
815+         t2 .start ()
816+         t1 .join ()
817+         t2 .join ()
818+         final_value  =  os .getenv ('MY_VAR' )
819+         self .assertEqual (final_value , "value2" )
820+ 
797821
798822    # XXX -follows a list of untested API 
799823    # make_legacy_pyc 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments