Try fixing zombie processes
This commit is contained in:
parent
63c109e616
commit
4733706eb1
2 changed files with 27 additions and 27 deletions
|
|
@ -123,13 +123,13 @@ def parallel_map(
|
|||
ignore_exceptions=ignore_exceptions,
|
||||
)
|
||||
should_stop.set()
|
||||
for p in processes:
|
||||
p.join()
|
||||
p.close()
|
||||
except:
|
||||
for p in processes:
|
||||
p.terminate()
|
||||
raise
|
||||
finally:
|
||||
for p in processes:
|
||||
p.join() # terminated processes have to be joined else they remain zombies
|
||||
p.close()
|
||||
input_queue.close()
|
||||
output_queue.close()
|
||||
|
|
|
|||
|
|
@ -61,31 +61,31 @@ class TestParallelMap(unittest.TestCase):
|
|||
)
|
||||
)
|
||||
|
||||
# def test_ignore_this_process_exception(self) -> None:
|
||||
# def my_generator():
|
||||
# yield 1
|
||||
# yield 2
|
||||
# yield 3
|
||||
# yield 1 / 0
|
||||
def test_ignore_this_process_exception(self) -> None:
|
||||
def my_generator():
|
||||
yield 1
|
||||
yield 2
|
||||
yield 3
|
||||
yield 1 / 0
|
||||
|
||||
# assert list(
|
||||
# parallel_map(
|
||||
# lambda v: v**2,
|
||||
# my_generator(),
|
||||
# concurrency=2,
|
||||
# chunk_size=2,
|
||||
# ignore_exceptions=True,
|
||||
# )
|
||||
# ) == [1, 4]
|
||||
# assert list(
|
||||
# parallel_map(
|
||||
# lambda v: v**2,
|
||||
# my_generator(),
|
||||
# concurrency=1,
|
||||
# chunk_size=2,
|
||||
# ignore_exceptions=True,
|
||||
# )
|
||||
# ) == [1, 4, 9]
|
||||
assert list(
|
||||
parallel_map(
|
||||
lambda v: v**2,
|
||||
my_generator(),
|
||||
concurrency=2,
|
||||
chunk_size=2,
|
||||
ignore_exceptions=True,
|
||||
)
|
||||
) == [1, 4]
|
||||
assert list(
|
||||
parallel_map(
|
||||
lambda v: v**2,
|
||||
my_generator(),
|
||||
concurrency=1,
|
||||
chunk_size=2,
|
||||
ignore_exceptions=True,
|
||||
)
|
||||
) == [1, 4, 9]
|
||||
|
||||
def test_worker_process_exception(self) -> None:
|
||||
def oh_no(_):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue