1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-06-26 16:45:52 +00:00

Remove forking support

* Third-party plugins have to be fork-safe
* Not supported on Windows
This commit is contained in:
Unrud 2020-02-19 09:50:02 +01:00
parent 3b99d64935
commit 698980d7be
2 changed files with 19 additions and 87 deletions

View file

@ -24,21 +24,15 @@ Log messages are sent to the first available target of:
- systemd-journald
- stderr
The logger is thread-safe and fork-safe.
"""
import contextlib
import io
import logging
import multiprocessing
import os
import sys
import tempfile
import threading
from radicale import pathutils
try:
import systemd.journal
except ImportError:
@ -64,14 +58,10 @@ class IdentLogRecordFactory:
def __init__(self, upstream_factory):
self.upstream_factory = upstream_factory
self.main_pid = os.getpid()
def __call__(self, *args, **kwargs):
record = self.upstream_factory(*args, **kwargs)
pid = os.getpid()
ident = "%x" % self.main_pid
if pid != self.main_pid:
ident += "%+x" % (pid - self.main_pid)
ident = "%x" % os.getpid()
main_thread = threading.main_thread()
current_thread = threading.current_thread()
if current_thread.name and main_thread != current_thread:
@ -80,27 +70,6 @@ class IdentLogRecordFactory:
return record
class RwLockWrapper():
def __init__(self):
self._file = tempfile.NamedTemporaryFile()
self._lock = pathutils.RwLock(self._file.name)
self._cm = None
def acquire(self, blocking=True):
assert self._cm is None
if not blocking:
raise NotImplementedError
cm = self._lock.acquire("w")
cm.__enter__()
self._cm = cm
def release(self):
assert self._cm is not None
self._cm.__exit__(None, None, None)
self._cm = None
class ThreadStreamsHandler(logging.Handler):
terminator = "\n"
@ -111,13 +80,6 @@ class ThreadStreamsHandler(logging.Handler):
self.fallback_stream = fallback_stream
self.fallback_handler = fallback_handler
def createLock(self):
try:
self.lock = multiprocessing.Lock()
except Exception:
# HACK: Workaround for Android
self.lock = RwLockWrapper()
def setFormatter(self, fmt):
super().setFormatter(fmt)
self.fallback_handler.setFormatter(fmt)