Skip to content

Commit 6d26a3f

Browse files
authored
Update to v0.1.6
`threading.Lock` added during `FileStream` flush.
2 parents b9bc056 + c47a830 commit 6d26a3f

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

fsLogger/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
__version__ = "0.1.5"
2+
__version__ = "0.1.6"
33
__doc__ = """
44
Logging utility v{}
55
Copyright (C) 2021 Fusion Solutions KFT <contact@fusionsolutions.io>

fsLogger/modules.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Builtin modules
22
from __future__ import annotations
33
import re, os, traceback
4+
from threading import Lock
45
from glob import glob
56
from datetime import datetime, timezone
67
from typing import List, Tuple, Any, Optional
@@ -72,9 +73,11 @@ def close(self) -> None:
7273
class FileStream(T_ModuleBase):
7374
fullPath:str
7475
stream:Any
76+
lock:Lock
7577
def __init__(self, fullPath:str):
7678
self.fullPath = fullPath
7779
self.stream = None
80+
self.lock = Lock()
7881
self.open()
7982
def open(self) -> None:
8083
try:
@@ -87,11 +90,12 @@ def open(self) -> None:
8790
traceback.print_exc()
8891
def write(self, data:str) -> None:
8992
if self.stream is not None:
90-
try:
91-
self.stream.write(data)
92-
self.stream.flush()
93-
except:
94-
traceback.print_exc()
93+
with self.lock:
94+
try:
95+
self.stream.write(data)
96+
self.stream.flush()
97+
except:
98+
traceback.print_exc()
9599
def emit(self, message:str) -> None:
96100
self.write(message)
97101
def close(self) -> None:

0 commit comments

Comments
 (0)