@@ -46,7 +46,11 @@ class BaseTestReader(object):
4646 Type ["maxminddb.extension.Reader" ], Type ["maxminddb.reader.Reader" ]
4747 ]
4848 use_ip_objects = False
49- mp = multiprocessing .get_context ("fork" )
49+
50+ # fork doesn't work on Windows and spawn would involve pickling the reader,
51+ # which isn't possible.
52+ if os .name != "nt" :
53+ mp = multiprocessing .get_context ("fork" )
5054
5155 def ipf (self , ip ):
5256 if self .use_ip_objects :
@@ -490,41 +494,43 @@ def test_closed_metadata(self):
490494 else :
491495 self .assertIsNotNone (metadata , "pure Python implementation returns value" )
492496
493- def test_multiprocessing (self ):
494- self ._check_concurrency (self .mp .Process )
495-
496- def test_threading (self ):
497- self ._check_concurrency (threading .Thread )
497+ if os .name != "nt" :
498498
499- def _check_concurrency (self , worker_class ):
500- reader = open_database (
501- "tests/data/test-data/GeoIP2-Domain-Test.mmdb" , self .mode
502- )
499+ def test_multiprocessing (self ):
500+ self ._check_concurrency (self .mp .Process )
503501
504- def lookup (pipe ):
505- try :
506- for i in range (32 ):
507- reader .get (self .ipf (f"65.115.240.{ i } " ))
508- pipe .send (1 )
509- except :
510- pipe .send (0 )
511- finally :
512- if worker_class is self .mp .Process :
513- reader .close ()
514- pipe .close ()
515-
516- pipes = [self .mp .Pipe () for _ in range (32 )]
517- procs = [worker_class (target = lookup , args = (c ,)) for (p , c ) in pipes ]
518- for proc in procs :
519- proc .start ()
520- for proc in procs :
521- proc .join ()
502+ def test_threading (self ):
503+ self ._check_concurrency (threading .Thread )
522504
523- reader .close ()
524-
525- count = sum ([p .recv () for (p , c ) in pipes ])
505+ def _check_concurrency (self , worker_class ):
506+ reader = open_database (
507+ "tests/data/test-data/GeoIP2-Domain-Test.mmdb" , self .mode
508+ )
526509
527- self .assertEqual (count , 32 , "expected number of successful lookups" )
510+ def lookup (pipe ):
511+ try :
512+ for i in range (32 ):
513+ reader .get (self .ipf (f"65.115.240.{ i } " ))
514+ pipe .send (1 )
515+ except :
516+ pipe .send (0 )
517+ finally :
518+ if worker_class is self .mp .Process :
519+ reader .close ()
520+ pipe .close ()
521+
522+ pipes = [self .mp .Pipe () for _ in range (32 )]
523+ procs = [worker_class (target = lookup , args = (c ,)) for (p , c ) in pipes ]
524+ for proc in procs :
525+ proc .start ()
526+ for proc in procs :
527+ proc .join ()
528+
529+ reader .close ()
530+
531+ count = sum ([p .recv () for (p , c ) in pipes ])
532+
533+ self .assertEqual (count , 32 , "expected number of successful lookups" )
528534
529535 def _check_metadata (self , reader , ip_version , record_size ):
530536 metadata = reader .metadata ()
0 commit comments