Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fd05c60

Browse files
committedMay 2, 2024·
Use spawn start method in multiprocessing programs
1 parent 5131e31 commit fd05c60

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed
 

‎sorts/odd_even_transposition_parallel.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
synchronization could be used.
1212
"""
1313

14-
from multiprocessing import Lock, Pipe, Process
14+
from multiprocessing import Lock, Pipe, Process, set_start_method
1515

1616
# lock used to ensure that two processes do not access a pipe at the same time
1717
# NOTE This breaks testing on build runner. May work better locally
@@ -153,6 +153,8 @@ def odd_even_transposition(arr):
153153

154154
# creates a reverse sorted list and sorts it
155155
def main():
156+
set_start_method("spawn") # spawn method is considered safer than fork
157+
156158
arr = list(range(10, 0, -1))
157159
print("Initial List")
158160
print(*arr)

0 commit comments

Comments
 (0)
Please sign in to comment.