nobody43 / zabbix-smartmontools

Disk SMART monitoring for Linux, FreeBSD and Windows. LLD, trapper.
The Unlicense
54 stars 19 forks source link

Don't use close_fds with subprocess.Popen #33

Open asomers opened 4 years ago

asomers commented 4 years ago

Python's subprocess.Popen's close_fds option is notoriously slow (see https://bugs.python.org/issue8052 and note that the issue is only fixed for systems that mount fdescfs, which isn't all of them ). Using fstat, I see that just before calling subprocess.Popen there are no file descriptors open whatsoever

$ sudo fstat -p 23537
USER     CMD          PID   FD MOUNT      INUM MODE         SZ|DV R/W
root     python3.7  23537 text /        305521 -r-xr-xr-x   15280  r
root     python3.7  23537 ctty /dev       1987 crw--w----   pts/0 rw
root     python3.7  23537   wd /usr/home 688140 drwxr-xr-x      23  r
root     python3.7  23537 root /             4 drwxr-xr-x      60  r

Accordingly, I suggest setting close_fds = False to improve performance on systems that don't mount fdescfs.

nobody43 commented 4 years ago

It was necessary for process spawning earlier. Let's try to do it your way since the timeout is gone.