Skip to content

Commit

Permalink
Don't use multiprocessing context manager in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed Jun 24, 2024
1 parent ade2851 commit 3f847b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 5 additions & 1 deletion brian2/tests/test_cpp_standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,12 @@ def test_change_parameters_multiprocessing():

import multiprocessing

with multiprocessing.Pool() as p:
p = multiprocessing.Pool()
try:
results = p.map(sim.run_sim, range(5))
finally:
p.close()
p.join()

for idx, result in zip(range(5), results):
v, w, x = result
Expand Down
12 changes: 10 additions & 2 deletions brian2/tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ def run_in_process_with_logger(x):
@pytest.mark.codegen_independent
def test_file_logging_multiprocessing():
logger.info("info message before multiprocessing")
p = multiprocessing.Pool()

with multiprocessing.Pool() as p:
try:
p.map(run_in_process, range(3))
finally:
p.close()
p.join()

BrianLogger.file_handler.flush()
assert os.path.isfile(BrianLogger.tmp_log)
Expand All @@ -75,8 +79,12 @@ def test_file_logging_multiprocessing():
def test_file_logging_multiprocessing_with_loggers():
logger.info("info message before multiprocessing")

with multiprocessing.Pool() as p:
p = multiprocessing.Pool()
try:
log_files = p.map(run_in_process_with_logger, range(3))
finally:
p.close()
p.join()

BrianLogger.file_handler.flush()
assert os.path.isfile(BrianLogger.tmp_log)
Expand Down

0 comments on commit 3f847b6

Please sign in to comment.