Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Linux] wait_procs seemingly ignoring timeout, TimeoutExpired thrown #1913

Closed
guille opened this issue Feb 4, 2021 · 0 comments · Fixed by #1917
Closed

[Linux] wait_procs seemingly ignoring timeout, TimeoutExpired thrown #1913

guille opened this issue Feb 4, 2021 · 0 comments · Fixed by #1917

Comments

@guille
Copy link
Contributor

guille commented Feb 4, 2021

Summary

  • OS: Ubuntu 18.04
  • Architecture: 64bit
  • Psutil version: Both 5.6.1 and 5.8.0
  • Python version: 3.7.5
  • Type: core

Description

The bug can be reproduced by creating these two files and running python a.py:

a.py:

import signal
import subprocess
import psutil
import time

my_process = subprocess.Popen(["python", "b.py"])
time.sleep(2)
try:
    my_process.send_signal(signal.SIGTERM)
    _, alive = psutil.wait_procs([my_process], timeout=5)
    if alive:
        alive[0].kill()
        psutil.wait_procs(alive, timeout=5)

except Exception as exc:
    print("Sigterm failed: ", str(exc))

b.py

import time
import signal

def handler(_signum, _frame):
    time.sleep(5)

signal.signal(signal.SIGTERM, handler)

time.sleep(50)

On my machine, this will print Sigterm failed Command '['python', 'b.py']' timed out after 1.0 seconds. Exception is an instance of subprocess.TimeoutExpired. By debugging a bit I see that this piece of code is where the exception initially appears. And since psutil.TimeoutExpired and subprocess.TimeoutExpired are different, it doesn't get caught.

I'm sure I'm doing something wrong as the example in the documentation is using a higher timeout, but I can't see the problem.

@guille guille added the bug label Feb 4, 2021
@github-actions github-actions bot added the linux label Feb 4, 2021
@guille guille changed the title [Linux] wait_procs seemingly ignoring timeout [Linux] wait_procs seemingly ignoring timeout, TimeoutExpire thrown Feb 4, 2021
@guille guille changed the title [Linux] wait_procs seemingly ignoring timeout, TimeoutExpire thrown [Linux] wait_procs seemingly ignoring timeout, TimeoutExpired thrown Feb 4, 2021
giampaolo pushed a commit that referenced this issue Feb 18, 2021
The function was exiting after one second due to a subprocess.TimeoutException

Fixes #1913

Signed-off-by: guille <guille@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant