Skip to content

Commit

Permalink
Fix removing simple queue in child processes (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstlmrk authored Sep 20, 2020
1 parent 296635c commit 44f6771
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,6 @@ ENV/

# VScode
.vscode/

# Idea IDE
.idea/
9 changes: 5 additions & 4 deletions loguru/_handler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import functools
import json
import os
import multiprocessing
from threading import Thread

Expand Down Expand Up @@ -66,7 +67,7 @@ def __init__(
self._queue = None
self._confirmation_event = None
self._confirmation_lock = None
self._owner_process = None
self._owner_process_pid = None
self._thread = None

if self._is_formatter_dynamic:
Expand All @@ -85,7 +86,7 @@ def __init__(
self._queue = multiprocessing.SimpleQueue()
self._confirmation_event = multiprocessing.Event()
self._confirmation_lock = multiprocessing.Lock()
self._owner_process = multiprocessing.current_process()
self._owner_process_pid = os.getpid()
self._thread = Thread(
target=self._queued_writer, daemon=True, name="loguru-writer-%d" % self._id
)
Expand Down Expand Up @@ -184,7 +185,7 @@ def stop(self):
with self._lock:
self._stopped = True
if self._enqueue:
if self._owner_process != multiprocessing.current_process():
if self._owner_process_pid != os.getpid():
return
self._queue.put(None)
self._thread.join()
Expand All @@ -201,7 +202,7 @@ def complete_queue(self):
self._confirmation_event.clear()

async def complete_async(self):
if self._enqueue and self._owner_process != multiprocessing.current_process():
if self._enqueue and self._owner_process_pid != os.getpid():
return

with self._lock:
Expand Down

0 comments on commit 44f6771

Please sign in to comment.