Skip to content

Commit

Permalink
refactor : network profiler
Browse files Browse the repository at this point in the history
Make the `network` profiler thread safe
  • Loading branch information
gibiw committed Sep 13, 2024
1 parent 8e46161 commit 07d047a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion qase-python-commons/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

## What's new

Add `clear` method to set the runtime to the base state.
- Add `clear` method to set the runtime to the base state.
- Make the `network` profiler thread safe.

# [email protected]

Expand Down
6 changes: 5 additions & 1 deletion qase-python-commons/src/qase/commons/profilers/network.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import threading
import uuid
from functools import wraps
from ..models.runtime import Runtime
Expand Down Expand Up @@ -108,11 +109,14 @@ def _log_response(response, url=None, *args, **kwargs):

class NetworkProfilerSingleton:
_instance = None
_lock = threading.Lock()

@staticmethod
def init(**kwargs):
if NetworkProfilerSingleton._instance is None:
NetworkProfilerSingleton._instance = NetworkProfiler(**kwargs)
with NetworkProfilerSingleton._lock:
if NetworkProfilerSingleton._instance is None:
NetworkProfilerSingleton._instance = NetworkProfiler(**kwargs)

@staticmethod
def get_instance() -> NetworkProfiler:
Expand Down

0 comments on commit 07d047a

Please sign in to comment.