2121from contextlib import suppress
2222from pathlib import Path
2323from queue import Queue
24- from subprocess import TimeoutExpired
24+ import subprocess
2525from tempfile import NamedTemporaryFile
2626from threading import RLock , Thread
2727from typing import Generator , List
2828
2929import numpy as np
30-
30+ from rich import print
3131from rich .progress import (
32- Progress ,
3332 BarColumn ,
33+ Progress ,
3434 TextColumn ,
3535 TimeElapsedColumn ,
3636 TimeRemainingColumn ,
3737)
38- from rich import print
3938
4039from .macroutils import AnyMacro , MacroCommand
4140from .tools import (
4948 getsubdirs ,
5049 make_hash ,
5150 parse_anybodycon_output ,
51+ running_in_snakemake ,
5252 silentremove ,
5353 winepath ,
5454)
5959 "Task" ,
6060]
6161
62- if ON_WINDOWS :
63- if "ANYPYTOOLS_DEBUG_USE_PYTHON_POPEN" in os .environ :
64- logger .warning ("Warning: Using Python's subprocess.Popen instead of JobPopen." )
65- from subprocess import Popen
66- else :
67- from .jobpopen import JobPopen as Popen
62+ logger = logging .getLogger ("abt.anypytools" )
6863
69- from subprocess import CREATE_NEW_PROCESS_GROUP
64+ if (
65+ ON_WINDOWS
66+ and not running_in_snakemake ()
67+ and "ANYPYTOOLS_DEBUG_USE_PYTHON_POPEN" not in os .environ
68+ ):
69+ from .jobpopen import JobPopen as Popen
7070else :
71+ print ("running with normal subprocess.Popen" )
72+ logger .warning ("running with normal subprocess.Popen" )
7173 from subprocess import Popen
7274
73- logger = logging .getLogger ("abt.anypytools" )
7475
7576_thread_lock = RLock ()
7677_KILLED_BY_ANYPYTOOLS = 10
@@ -219,7 +220,7 @@ def execute_anybodycon(
219220 ctypes .windll .kernel32 .SetErrorMode (SEM_NOGPFAULTERRORBOX )
220221 subprocess_flags = 0x8000000 # win32con.CREATE_NO_WINDOW?
221222 subprocess_flags |= priority
222- subprocess_flags |= CREATE_NEW_PROCESS_GROUP
223+ subprocess_flags |= subprocess . CREATE_NEW_PROCESS_GROUP
223224 extra_kwargs = {"creationflags" : subprocess_flags }
224225
225226 cmd = [
@@ -284,7 +285,7 @@ def execute_anybodycon(
284285 try :
285286 proc .wait (timeout = timeout )
286287 retcode = ctypes .c_int32 (proc .returncode ).value
287- except TimeoutExpired :
288+ except subprocess . TimeoutExpired :
288289 proc .kill ()
289290 proc .communicate ()
290291 retcode = _TIMEDOUT_BY_ANYPYTOOLS
@@ -296,7 +297,7 @@ def execute_anybodycon(
296297 finally :
297298 if retcode is None :
298299 proc .kill ()
299- if ON_WINDOWS :
300+ if ON_WINDOWS and hasattr ( proc , "_close_job_object" ) :
300301 proc ._close_job_object (proc ._win32_job )
301302 else :
302303 subprocess_container .remove (proc .pid )
0 commit comments