jenkins-bot submitted this change.

View Change


Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] use pathlib.write_text instead of codecs in daemonize.py

Change-Id: I63343aa139d48ec99f676c2276fcc7aa7a5cc59d
---
M pywikibot/daemonize.py
1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/pywikibot/daemonize.py b/pywikibot/daemonize.py
index 6b433e8..1ed97bc 100644
--- a/pywikibot/daemonize.py
+++ b/pywikibot/daemonize.py
@@ -4,20 +4,20 @@
#
# Distributed under the terms of the MIT license.
#
-import codecs
import os
import stat
import sys
+from pathlib import Path
from typing import Optional


is_daemon = False


-def daemonize(close_fd: bool = True, chdir: bool = True,
+def daemonize(close_fd: bool = True,
+ chdir: bool = True,
redirect_std: Optional[str] = None) -> None:
- """
- Daemonize the current process.
+ """Daemonize the current process.

Only works on POSIX compatible operating systems.
The process will fork to the background and return control to terminal.
@@ -58,9 +58,9 @@
return

# Write out the pid
- path = os.path.basename(sys.argv[0]) + '.pid'
- with codecs.open(path, 'w', 'utf-8') as f:
- f.write(str(pid))
+ path = Path(Path(sys.argv[0]).name).with_suffix('.pid')
+ path.write_text(str(pid), encoding='uft-8')
+
# Exit to return control to the terminal
# os._exit to prevent the cleanup to run
os._exit(os.EX_OK)

To view, visit change 862228. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I63343aa139d48ec99f676c2276fcc7aa7a5cc59d
Gerrit-Change-Number: 862228
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged