pyinvoke / invoke

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

invoke 2.0.0 fails to properly cleanup timer on runner #910

Closed puerkito66 closed 1 year ago

puerkito66 commented 1 year ago

Following the commit history looks like https://github.com/pyinvoke/invoke/commit/87d337084b20640a3e00bf810b769eaa73f58e8e is the root cause of https://github.com/fabric/fabric/issues/2241

Local runner is not calling their parent stop() but it's calling it's propper stop() method, thus making the timer thread is never cancelled.

According to this commnet calling the parent stop() should solve this problem.

https://github.com/pyinvoke/invoke/blob/7184e16d8c27f3fd92b2e9f3c3059c41c0366472/invoke/runners.py#L1330-L1340

figarocorso commented 1 year ago

I think I hit this issue as well.

Just adding a timeout to any run will hit this issue. Here how to reproduce:

(onprem) /tmp$ cat cow.sh 
#!/bin/bash
echo "cow 1"
sleep 2
echo "cow 2"
(onprem) /tmp$ cat cow.py
import invoke

invoke.run("/tmp/cow.sh", timeout=10, echo=True)
(onprem) /tmp$ pip freeze | grep "invoke"
invoke==2.0.0
(onprem) /tmp$ time python cow.py 
/tmp/cow.sh
cow 1
cow 2
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 1378, in run
    self.function(*self.args, **self.kwargs)
  File "/home/figarocorso/venvs/onprem/lib/python3.10/site-packages/invoke/runners.py", line 1292, in kill
    os.kill(pid, signal.SIGKILL)
ProcessLookupError: [Errno 3] No such process

real    0m10,112s
user    0m0,142s
sys 0m0,012s
(onprem) /tmp$ pip install invoke==1.7.3
Collecting invoke==1.7.3
  Downloading invoke-1.7.3-py3-none-any.whl (216 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 216.4/216.4 kB 3.8 MB/s eta 0:00:00
Installing collected packages: invoke
  Attempting uninstall: invoke
    Found existing installation: invoke 2.0.0
    Uninstalling invoke-2.0.0:
      Successfully uninstalled invoke-2.0.0
Successfully installed invoke-1.7.3

[notice] A new release of pip available: 22.1.2 -> 23.0
[notice] To update, run: pip install --upgrade pip
(onprem) /tmp$ time python cow.py 
/tmp/cow.sh
cow 1
cow 2

real    0m2,119s
user    0m0,138s
sys 0m0,023s
(onprem) /tmp$ 
bitprophet commented 1 year ago

Thanks for the report, just pushed a fix and will release shortly.