Skip to content

Commit

Permalink
Improve docs and impl. of PYLAPROF_DISABLE
Browse files Browse the repository at this point in the history
The documentation of `PYLAPROF_DISABLE` was a bit too verbose and
repetitive.

Its logic was encapsulated into `_disabled` to avoid to clutter the
implementation of `run`.
  • Loading branch information
Giuseppe Lumia committed Dec 4, 2021
1 parent f45a9f4 commit c7213e7
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions pylaprof/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,7 @@ def __init__(self, period=0.01, single=True, min_time=0, sampler=None, storer=No
Defaults to an instance of `S3` if none.
Profiler's activity can be controlled through the `PYLAPROF_DISABLE` environment
variable: if it is set to 'true' then profiler's context will be a noop (but
existing profiling activity will continue until the profiled function doesn't
return). This can be useful if you want to profile a function you use in
production: just decorate it and turn on/off profiling through this environment
variable.
variable: if it is set to 'true' then profiler's context will be a noop.
"""
super().__init__()

Expand Down Expand Up @@ -212,16 +208,19 @@ def __exit__(self, exc_type, exc_val, exc_tb):
self.stop()
self.join()

def _disabled(self):
return os.getenv("PYLAPROF_DISABLE", "false").lower() in {
"y",
"yes",
"t",
"true",
"on",
"1",
}

def run(self):
try:
if os.getenv("PYLAPROF_DISABLE", "false").lower() in {
"y",
"yes",
"t",
"true",
"on",
"1",
}:
if self._disabled():
self._stop_event.clear()
self.clean_exit = True
return
Expand Down

0 comments on commit c7213e7

Please sign in to comment.