@@ -42,9 +42,9 @@ pub unsafe fn setup(build: &mut crate::Build) {
4242#[ cfg( windows) ]  
4343mod  for_windows { 
4444    use  std:: ffi:: c_void; 
45-     use  std:: { env ,   io,  mem} ; 
45+     use  std:: { io,  mem} ; 
4646
47-     use  windows:: Win32 :: Foundation :: { CloseHandle ,   DUPLICATE_SAME_ACCESS ,   DuplicateHandle ,   HANDLE } ; 
47+     use  windows:: Win32 :: Foundation :: CloseHandle ; 
4848    use  windows:: Win32 :: System :: Diagnostics :: Debug :: { 
4949        SEM_NOGPFAULTERRORBOX ,  SetErrorMode ,  THREAD_ERROR_MODE , 
5050    } ; 
@@ -53,9 +53,7 @@ mod for_windows {
5353        JOB_OBJECT_LIMIT_PRIORITY_CLASS ,  JOBOBJECT_EXTENDED_LIMIT_INFORMATION , 
5454        JobObjectExtendedLimitInformation ,  SetInformationJobObject , 
5555    } ; 
56-     use  windows:: Win32 :: System :: Threading :: { 
57-         BELOW_NORMAL_PRIORITY_CLASS ,  GetCurrentProcess ,  OpenProcess ,  PROCESS_DUP_HANDLE , 
58-     } ; 
56+     use  windows:: Win32 :: System :: Threading :: { BELOW_NORMAL_PRIORITY_CLASS ,  GetCurrentProcess } ; 
5957    use  windows:: core:: PCWSTR ; 
6058
6159    use  crate :: Build ; 
@@ -95,49 +93,8 @@ mod for_windows {
9593            return ; 
9694        } 
9795
98-         // If we've got a parent process (e.g., the python script that called us) 
99-         // then move ownership of this job object up to them. That way if the python 
100-         // script is killed (e.g., via ctrl-c) then we'll all be torn down. 
101-         // 
102-         // If we don't have a parent (e.g., this was run directly) then we 
103-         // intentionally leak the job object handle. When our process exits 
96+         // Note: we intentionally leak the job object handle. When our process exits 
10497        // (normally or abnormally) it will close the handle implicitly, causing all 
10598        // processes in the job to be cleaned up. 
106-         let  pid = match  env:: var ( "BOOTSTRAP_PARENT_ID" )  { 
107-             Ok ( s)  => s, 
108-             Err ( ..)  => return , 
109-         } ; 
110- 
111-         let  parent = match  OpenProcess ( PROCESS_DUP_HANDLE ,  false ,  pid. parse ( ) . unwrap ( ) ) . ok ( )  { 
112-             Some ( parent)  => parent, 
113-             _ => { 
114-                 // If we get a null parent pointer here, it is possible that either 
115-                 // we have an invalid pid or the parent process has been closed. 
116-                 // Since the first case rarely happens 
117-                 // (only when wrongly setting the environmental variable), 
118-                 // it might be better to improve the experience of the second case 
119-                 // when users have interrupted the parent process and we haven't finish 
120-                 // duplicating the handle yet. 
121-                 return ; 
122-             } 
123-         } ; 
124- 
125-         let  mut  parent_handle = HANDLE :: default ( ) ; 
126-         // If this fails, well at least we tried! An example of DuplicateHandle 
127-         // failing in the past has been when the wrong python2 package spawned this 
128-         // build system (e.g., the `python2` package in MSYS instead of 
129-         // `mingw-w64-x86_64-python2`). Not sure why it failed, but the "failure 
130-         // mode" here is that we only clean everything up when the build system 
131-         // dies, not when the python parent does, so not too bad. 
132-         let  _ = DuplicateHandle ( 
133-             GetCurrentProcess ( ) , 
134-             job, 
135-             parent, 
136-             & mut  parent_handle, 
137-             0 , 
138-             false , 
139-             DUPLICATE_SAME_ACCESS , 
140-         ) ; 
141-         CloseHandle ( parent) . ok ( ) ; 
14299    } 
143100} 
0 commit comments