@@ -346,14 +346,6 @@ def _exec(self, execute_file, _id):
346346 'LD_PRELOAD' : f'{ _sandbox_path } /lib/sandbox.so' ,
347347 '_ID' : _id ,
348348 }}
349- def _set_resource_limit ():
350- if not _enable_sandbox or IS_WINDOWS or not resource :
351- return
352- with suppress (Exception ):
353- resource .setrlimit (resource .RLIMIT_AS , (_process_limit_mem_mb * 1024 * 1024 ,) * 2 )
354- with suppress (Exception ):
355- if hasattr (os , 'sched_setaffinity' ) and hasattr (os , 'sched_getaffinity' ):
356- os .sched_setaffinity (0 , set (random .sample (list (os .sched_getaffinity (0 )), _process_limit_cpu_cores )))
357349 try :
358350 # Windows 不支持 preexec_fn 参数
359351 if IS_WINDOWS :
@@ -365,6 +357,10 @@ def _set_resource_limit():
365357 ** kwargs
366358 )
367359 else :
360+ def _set_resource_limit ():
361+ if not _enable_sandbox or not sys .platform .startswith ("linux" ): return
362+ with suppress (Exception ): resource .setrlimit (resource .RLIMIT_AS , (_process_limit_mem_mb * 1024 * 1024 ,) * 2 )
363+ with suppress (Exception ): os .sched_setaffinity (0 , set (random .sample (list (os .sched_getaffinity (0 )), _process_limit_cpu_cores )))
368364 subprocess_result = subprocess .run (
369365 [sys .executable , execute_file ],
370366 timeout = _process_limit_timeout_seconds ,
0 commit comments