Skip to content

Commit b511290

Browse files
authoredJul 18, 2023
Merge pull request #116 from tjni/fix-multiprocessing-test-mac
Fix multiprocessing tests on macOS.
2 parents c1f4156 + f5cc21f commit b511290

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed
 

Diff for: ‎tests/reader_test.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
import ipaddress
5+
import multiprocessing
56
import os
67
import pathlib
78
import threading
@@ -45,6 +46,7 @@ class BaseTestReader(object):
4546
Type["maxminddb.extension.Reader"], Type["maxminddb.reader.Reader"]
4647
]
4748
use_ip_objects = False
49+
mp = multiprocessing.get_context("fork")
4850

4951
def ipf(self, ip):
5052
if self.use_ip_objects:
@@ -441,7 +443,7 @@ def test_closed_metadata(self):
441443
self.assertIsNotNone(metadata, "pure Python implementation returns value")
442444

443445
def test_multiprocessing(self):
444-
self._check_concurrency(Process)
446+
self._check_concurrency(self.mp.Process)
445447

446448
def test_threading(self):
447449
self._check_concurrency(threading.Thread)
@@ -459,11 +461,11 @@ def lookup(pipe):
459461
except:
460462
pipe.send(0)
461463
finally:
462-
if worker_class is Process:
464+
if worker_class is self.mp.Process:
463465
reader.close()
464466
pipe.close()
465467

466-
pipes = [Pipe() for _ in range(32)]
468+
pipes = [self.mp.Pipe() for _ in range(32)]
467469
procs = [worker_class(target=lookup, args=(c,)) for (p, c) in pipes]
468470
for proc in procs:
469471
proc.start()

0 commit comments

Comments
 (0)
Please sign in to comment.