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,
|
ignore_exceptions=ignore_exceptions,
|
||||||
)
|
)
|
||||||
should_stop.set()
|
should_stop.set()
|
||||||
for p in processes:
|
|
||||||
p.join()
|
|
||||||
p.close()
|
|
||||||
except:
|
except:
|
||||||
for p in processes:
|
for p in processes:
|
||||||
p.terminate()
|
p.terminate()
|
||||||
raise
|
raise
|
||||||
finally:
|
finally:
|
||||||
|
for p in processes:
|
||||||
|
p.join() # terminated processes have to be joined else they remain zombies
|
||||||
|
p.close()
|
||||||
input_queue.close()
|
input_queue.close()
|
||||||
output_queue.close()
|
output_queue.close()
|
||||||
|
|
|
||||||
|
|
@ -61,31 +61,31 @@ class TestParallelMap(unittest.TestCase):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# def test_ignore_this_process_exception(self) -> None:
|
def test_ignore_this_process_exception(self) -> None:
|
||||||
# def my_generator():
|
def my_generator():
|
||||||
# yield 1
|
yield 1
|
||||||
# yield 2
|
yield 2
|
||||||
# yield 3
|
yield 3
|
||||||
# yield 1 / 0
|
yield 1 / 0
|
||||||
|
|
||||||
# assert list(
|
assert list(
|
||||||
# parallel_map(
|
parallel_map(
|
||||||
# lambda v: v**2,
|
lambda v: v**2,
|
||||||
# my_generator(),
|
my_generator(),
|
||||||
# concurrency=2,
|
concurrency=2,
|
||||||
# chunk_size=2,
|
chunk_size=2,
|
||||||
# ignore_exceptions=True,
|
ignore_exceptions=True,
|
||||||
# )
|
)
|
||||||
# ) == [1, 4]
|
) == [1, 4]
|
||||||
# assert list(
|
assert list(
|
||||||
# parallel_map(
|
parallel_map(
|
||||||
# lambda v: v**2,
|
lambda v: v**2,
|
||||||
# my_generator(),
|
my_generator(),
|
||||||
# concurrency=1,
|
concurrency=1,
|
||||||
# chunk_size=2,
|
chunk_size=2,
|
||||||
# ignore_exceptions=True,
|
ignore_exceptions=True,
|
||||||
# )
|
)
|
||||||
# ) == [1, 4, 9]
|
) == [1, 4, 9]
|
||||||
|
|
||||||
def test_worker_process_exception(self) -> None:
|
def test_worker_process_exception(self) -> None:
|
||||||
def oh_no(_):
|
def oh_no(_):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue