Skip to content

Commit

Permalink
Fixed multiprocessing integration tests not running on Mac (#8727)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nusnus committed Dec 17, 2023
1 parent f5d19af commit d1350f9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions t/integration/test_tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
import platform
import time
from datetime import datetime, timedelta
from multiprocessing import set_start_method
from time import perf_counter, sleep
from uuid import uuid4

Expand Down Expand Up @@ -29,6 +31,16 @@ def flaky(fn):
return _timeout(_flaky(fn))


def set_multiprocessing_start_method():
"""Set multiprocessing start method to 'fork' if not on Linux."""
if platform.system() != 'Linux':
try:
set_start_method('fork')
except RuntimeError:
# The method is already set
pass


class test_class_based_tasks:

@flaky
Expand Down Expand Up @@ -89,6 +101,8 @@ def test_basic_task(self, manager):
@flaky
def test_multiprocess_producer(self, manager):
"""Testing multiple processes calling tasks."""
set_multiprocessing_start_method()

from multiprocessing import Pool
pool = Pool(20)
ret = pool.map(_producer, range(120))
Expand All @@ -97,6 +111,8 @@ def test_multiprocess_producer(self, manager):
@flaky
def test_multithread_producer(self, manager):
"""Testing multiple threads calling tasks."""
set_multiprocessing_start_method()

from multiprocessing.pool import ThreadPool
pool = ThreadPool(20)
ret = pool.map(_producer, range(120))
Expand Down

0 comments on commit d1350f9

Please sign in to comment.