jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1162834?usp=email )
Change subject: IMPR: Use an IntEnum for standard file descriptors instead of
integers
......................................................................
IMPR: Use an IntEnum for standard file descriptors instead of integers
Also fix utf-8 encoding
Change-Id: Ib00466f4b56e9f8335e5ae2fc046c6339b4f62ae
---
M pywikibot/daemonize.py
1 file changed, 19 insertions(+), 7 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/daemonize.py b/pywikibot/daemonize.py
index 9b8df1d..ea90c16 100644
--- a/pywikibot/daemonize.py
+++ b/pywikibot/daemonize.py
@@ -1,6 +1,6 @@
"""Module to daemonize the current process on Unix."""
#
-# (C) Pywikibot team, 2007-2022
+# (C) Pywikibot team, 2007-2025
#
# Distributed under the terms of the MIT license.
#
@@ -9,9 +9,19 @@
import os
import stat
import sys
+from enum import IntEnum
from pathlib import Path
+class StandardFD(IntEnum):
+
+ """File descriptors for standard input, output and error."""
+
+ STDIN = 0
+ STDOUT = 1
+ STDERR = 2
+
+
is_daemon = False
@@ -35,15 +45,16 @@
# Fork again to prevent the process from acquiring a
# controlling terminal
pid = os.fork()
+
if not pid:
global is_daemon
is_daemon = True
if close_fd:
- os.close(0)
- os.close(1)
- os.close(2)
+ for fd in StandardFD:
+ os.close(fd)
os.open('/dev/null', os.O_RDWR)
+
if redirect_std:
# R/W mode without execute flags
mode = (stat.S_IRUSR | stat.S_IWUSR
@@ -53,15 +64,16 @@
os.O_WRONLY | os.O_APPEND | os.O_CREAT,
mode)
else:
- os.dup2(0, 1)
- os.dup2(1, 2)
+ os.dup2(StandardFD.STDIN, StandardFD.STDOUT)
+ os.dup2(StandardFD.STDOUT, StandardFD.STDERR)
+
if chdir:
os.chdir('/')
return
# Write out the pid
path = Path(Path(sys.argv[0]).name).with_suffix('.pid')
- path.write_text(str(pid), encoding='uft-8')
+ path.write_text(str(pid), encoding='utf-8')
# Exit to return control to the terminal
# os._exit to prevent the cleanup to run
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1162834?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ib00466f4b56e9f8335e5ae2fc046c6339b4f62ae
Gerrit-Change-Number: 1162834
Gerrit-PatchSet: 6
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]