Please help me with the error. I have a simple code that I run on Linux.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import daemon
import sys
from traceback import format_exc
def run_main_function():
print("Hello")
try:
with daemon.DaemonContext():
run_main_function()
except:
print(sys.stdin)
print(format_exc())
The script is unstable. The script sometimes fails and sometimes executes successfully. I ask for help in solving the problem.
None
Traceback (most recent call last):
File "/usr/lib/zabbix/externalscripts/logstash_stats.py", line 18, in <module>
with daemon.DaemonContext():
File "/usr/local/lib/python3.9/site-packages/daemon/daemon.py", line 249, in __init__
detach_process = is_detach_process_context_required()
File "/usr/local/lib/python3.9/site-packages/daemon/daemon.py", line 817, in is_detach_process_context_required
if is_process_started_by_init() or is_process_started_by_superserver():
File "/usr/local/lib/python3.9/site-packages/daemon/daemon.py", line 795, in is_process_started_by_superserver
if is_socket_file(sys.__stdin__):
File "/usr/local/lib/python3.9/site-packages/daemon/daemon.py", line 759, in is_socket_file
file_fd = file.fileno()
AttributeError: 'NoneType' object has no attribute 'fileno'
I tried to set stdin manually, but it didn't work.
Google search didn't help me.
New details: The problem is not related to the daemon library. My script periodically returns NoneType when I execute simple code.
import sys
print(sys.stdin)
return:
None
My script calls zabbix. The rights to the script were issued correctly. I do not know what the problem is.
chown zabbix:zabbix /path/script
chmod 0777 /path/scrypt
Tell me what can be done?