Skip to content

Commit 619cfad

Browse files
committed
perf
1 parent 88fde89 commit 619cfad

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Diff for: httpdbg/hooks/external.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@
1616

1717
@contextmanager
1818
def watcher_external(records: HTTPRecords) -> Generator[HTTPRecords, None, None]:
19-
remove_environment_variable = False
20-
2119
if HTTPDBG_MULTIPROCESS_DIR not in os.environ:
2220
with tempfile.TemporaryDirectory(prefix="httpdbg") as httpdbg_multiprocess_dir:
2321

2422
logger().info(f"watcher_external {httpdbg_multiprocess_dir}")
25-
remove_environment_variable = True
2623
os.environ[HTTPDBG_MULTIPROCESS_DIR] = httpdbg_multiprocess_dir
2724

2825
# we use a custom sitecustomize.py script to record the request in the subprocesses.
@@ -52,10 +49,6 @@ def watcher_external(records: HTTPRecords) -> Generator[HTTPRecords, None, None]
5249
yield records
5350
finally:
5451
watcher.shutdown()
55-
if remove_environment_variable and (
56-
HTTPDBG_MULTIPROCESS_DIR in os.environ
57-
):
58-
del os.environ[HTTPDBG_MULTIPROCESS_DIR]
5952
else:
6053
yield records
6154

@@ -77,7 +70,7 @@ def load_dump(self):
7770
self.records.groups.update(newrecords.groups)
7871

7972
def run(self):
80-
while self._running and (HTTPDBG_MULTIPROCESS_DIR in os.environ):
73+
while self._running:
8174
self.load_dump()
8275
time.sleep(self.delay)
8376

Diff for: tests/test_multiprocess.py

+9
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
import pytest
44

55
from httpdbg import httprecord
6+
from httpdbg.env import HTTPDBG_MULTIPROCESS_DIR
67
from httpdbg.mode_script import run_script
78

89

910
@pytest.mark.script
1011
def test_run_script_multithread(httpbin):
12+
13+
if HTTPDBG_MULTIPROCESS_DIR in os.environ:
14+
del os.environ[HTTPDBG_MULTIPROCESS_DIR]
15+
1116
with httprecord() as records:
1217
os.environ["HTTPDBG_TEST_MULTITHREAD_BASE_URL"] = httpbin.url
1318
script_to_run = os.path.join(
@@ -24,6 +29,10 @@ def test_run_script_multithread(httpbin):
2429

2530
@pytest.mark.script
2631
def test_run_script_multiprocess(httpbin):
32+
33+
if HTTPDBG_MULTIPROCESS_DIR in os.environ:
34+
del os.environ[HTTPDBG_MULTIPROCESS_DIR]
35+
2736
with httprecord() as records:
2837
os.environ["HTTPDBG_TEST_MULTIPROCESS_BASE_URL"] = httpbin.url
2938
script_to_run = os.path.join(

0 commit comments

Comments
 (0)