pyinvoke / invoke

Pythonic task management & command execution.
http://pyinvoke.org
BSD 2-Clause "Simplified" License
4.32k stars 365 forks source link

Cannot timeout on Windows with Runner.run #867

Open shachibista opened 1 year ago

shachibista commented 1 year ago

Hi!

I am trying to timeout a command run using Runnner.run(..., timeout=3) (invoke >= 1.6.0, python == 3.7.11) but under Windows 10 I get the following error:

Traceback (most recent call last):
  File "~\AppData\Local\Continuum\anaconda3\envs\Project\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "~\AppData\Local\Continuum\anaconda3\envs\Project\lib\threading.py", line 1177, in run
    self.function(*self.args, **self.kwargs)
  File "~\AppData\Local\Continuum\anaconda3\envs\Project\lib\site-packages\invoke\runners.py", line 1313, in kill
    os.kill(pid, signal.SIGKILL)
AttributeError: module 'signal' has no attribute 'SIGKILL'

It seems that SIGKILL is not available in windows: https://docs.python.org/3/library/signal.html#signal.SIGKILL

Here is some more context, potential solutions and caveats: https://stackoverflow.com/a/35792192