mirror of
https://github.com/Kozea/Radicale.git
synced 2025-04-07 07:07:36 +03:00
Implement fallback for multiprocessing module
module is not working on Android
This commit is contained in:
parent
e5c4373606
commit
edc20ed510
2 changed files with 43 additions and 4 deletions
|
@ -29,8 +29,11 @@ import logging
|
|||
import multiprocessing
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
|
||||
from radicale import pathutils
|
||||
|
||||
try:
|
||||
import systemd.journal
|
||||
except ImportError:
|
||||
|
@ -72,6 +75,27 @@ 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"
|
||||
|
@ -83,7 +107,11 @@ class ThreadStreamsHandler(logging.Handler):
|
|||
self.fallback_handler = fallback_handler
|
||||
|
||||
def createLock(self):
|
||||
self.lock = multiprocessing.Lock()
|
||||
try:
|
||||
self.lock = multiprocessing.Lock()
|
||||
except Exception:
|
||||
# HACK: Workaround for Android
|
||||
self.lock = RwLockWrapper()
|
||||
|
||||
def setFormatter(self, form):
|
||||
super().setFormatter(form)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue