File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ import multiprocessing
2+ import os
13import sys
24import unittest
35
46from importlib_metadata import (
7+ FastPath ,
58 PackageNotFoundError ,
69 distribution ,
710 distributions ,
@@ -47,6 +50,37 @@ def test_one_distribution(self):
4750 dists = list (distributions (path = sys .path [:1 ]))
4851 assert len (dists ) == 1
4952
53+ @unittest .skipUnless (
54+ hasattr (os , 'register_at_fork' )
55+ and 'fork' in multiprocessing .get_all_start_methods (),
56+ 'requires fork-based multiprocessing support' ,
57+ )
58+ def test_fastpath_cache_cleared_in_forked_child (self ):
59+ zip_path = sys .path [0 ]
60+
61+ FastPath (zip_path )
62+ self .assertEqual (FastPath .__new__ .cache_info ().currsize , 1 )
63+
64+ ctx = multiprocessing .get_context ('fork' )
65+ parent_conn , child_conn = ctx .Pipe ()
66+
67+ def child (conn , root ):
68+ try :
69+ before = FastPath .__new__ .cache_info ().currsize
70+ FastPath (root )
71+ after = FastPath .__new__ .cache_info ().currsize
72+ conn .send ((before , after ))
73+ finally :
74+ conn .close ()
75+
76+ proc = ctx .Process (target = child , args = (child_conn , zip_path ))
77+ proc .start ()
78+ child_conn .close ()
79+ cache_sizes = parent_conn .recv ()
80+ proc .join ()
81+
82+ self .assertEqual (cache_sizes , (0 , 1 ))
83+
5084
5185class TestEgg (TestZip ):
5286 def setUp (self ):
You can’t perform that action at this time.
0 commit comments