Skip to content

Commit

Permalink
Fixed multithreading bug with StdStreamCaptureLogger (#762)
Browse files Browse the repository at this point in the history
* Fixed multithreading bug with StdStreamCaptureLogger

* fix changelog
  • Loading branch information
pkasprzyk authored Nov 25, 2021
1 parent 081ca61 commit 873fc8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## neptune-client 0.13.3

### Fixes
- Fixed multithreading bug with StdStreamCaptureLogger ([#762](https://github.com/neptune-ai/neptune-client/pull/762))

## neptune-client 0.13.2

### Fixes
Expand Down
6 changes: 3 additions & 3 deletions neptune/new/internal/streams/std_stream_capture_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ def __init__(self, run: Run, attribute_name: str, stream: TextIO):
self._logger = NeptuneLogger(run, attribute_name)
self.stream = stream
self._thread_local = threading.local()
self._thread_local.enabled = True
self.enabled = True

def write(self, data: str):
if not hasattr(self._thread_local, "inside_write"):
self._thread_local.inside_write = False

self.stream.write(data)
if self._thread_local.enabled and not self._thread_local.inside_write:
if self.enabled and not self._thread_local.inside_write:
try:
self._thread_local.inside_write = True
self._logger.log(data)
Expand All @@ -46,7 +46,7 @@ def __getattr__(self, attr):
return getattr(self.stream, attr)

def close(self):
self._thread_local.enabled = False
self.enabled = False


class StdoutCaptureLogger(StdStreamCaptureLogger):
Expand Down

0 comments on commit 873fc8e

Please sign in to comment.