2222import threading
2323
2424import pytest
25- from helpers .child_processes import child_timeout_sec , kill_subprocesses
25+ from helpers .child_processes import child_timeout_sec , kill_subprocesses , noop , run_child , warmup_multiprocessing
2626from helpers .contexts import assert_no_cuda_warning
2727
2828from cuda .bindings import driver
@@ -149,20 +149,6 @@ class _CustomResource(VirtualMemoryResource):
149149 """A subclass, to check that pickling preserves the type."""
150150
151151
152- def _run_child (target , * args ):
153- """Run ``target(*args)`` in a spawned child and fail if it does not exit cleanly."""
154- process = mp .Process (target = target , args = args )
155- process .start ()
156- process .join (timeout = CHILD_TIMEOUT_SEC )
157- survivors = kill_subprocesses (process )
158- assert not survivors , "child did not exit within timeout"
159- assert process .exitcode == 0 , f"child exited with { process .exitcode } "
160-
161-
162- def _noop (* args ):
163- pass
164-
165-
166152def _close_argument (buffer ):
167153 buffer .close ()
168154
@@ -260,7 +246,7 @@ def test_main(self, vmm_ipc_device):
260246 assert _open_fds () == fds_before + 3
261247 fds = [int (handle ) for handle in desc ._handles ]
262248
263- _run_child (self .child_main , device .device_id , desc , gran , queue )
249+ run_child (self .child_main , device .device_id , desc , gran , queue )
264250 result = queue .get (timeout = CHILD_TIMEOUT_SEC )
265251 assert result ["chunks" ] == [bytes ([value ]) * 16 for value in values ]
266252 assert result ["released" ] is True
@@ -311,7 +297,7 @@ def test_main(self, vmm_ipc_device_x2):
311297
312298 peers_possible = dev1 .can_access_peer (dev0 )
313299 queue = mp .Queue ()
314- _run_child (self .child_main , dev0 .device_id , dev1 .device_id , desc , peers_possible , queue )
300+ run_child (self .child_main , dev0 .device_id , dev1 .device_id , desc , peers_possible , queue )
315301 result = queue .get (timeout = CHILD_TIMEOUT_SEC )
316302 assert f"device { dev0 .device_id } " in result ["wrong_device" ]
317303 assert result ["device_id" ] == dev1 .device_id
@@ -495,7 +481,7 @@ def test_export_and_pickling_raise_before_any_driver_call(self, vmm_ipc_device):
495481 with parent_conn , child_conn , pytest .raises (RuntimeError , match = _REEXPORT_MESSAGE ):
496482 parent_conn .send (imported )
497483 with pytest .raises (RuntimeError , match = _REEXPORT_MESSAGE ):
498- mp .Process (target = _noop , args = (imported ,)).start ()
484+ mp .Process (target = noop , args = (imported ,)).start ()
499485 # The original descriptor still serves new importers, and the data is intact.
500486 _fill (buf , 0x3C )
501487 alias = Buffer .from_ipc_descriptor (mr , desc , stream = stream )
@@ -589,9 +575,7 @@ def test_exporter_holds_none_without_a_descriptor(self, vmm_ipc_device):
589575 @pytest .mark .thread_unsafe (reason = "counts process-global file descriptors" )
590576 def test_process_argument_releases_with_the_process_object (self , vmm_ipc_device ):
591577 """A buffer passed to a spawned Process imports there; its descriptor goes when the Process object does."""
592- # The first spawn opens a process-wide resource-tracker pipe, which
593- # outlives Process objects. Start it before taking the descriptor baseline.
594- _run_child (_noop )
578+ warmup_multiprocessing ()
595579 device = vmm_ipc_device
596580 mr = _resource (device )
597581 with mr .allocate (1 ) as buf :
@@ -926,7 +910,7 @@ def test_round_trip(self, vmm_ipc_device):
926910 assert alias .is_mapped
927911 alias .close ()
928912 queue = mp .Queue ()
929- _run_child (self .child_main , device .device_id , desc , queue )
913+ run_child (self .child_main , device .device_id , desc , queue )
930914 assert queue .get (timeout = CHILD_TIMEOUT_SEC ) == {"size" : 0 , "is_mapped" : True }
931915 empty .close ()
932916
@@ -948,7 +932,7 @@ def test_imported_buffer_feeds_a_consumer(self, vmm_ipc_device):
948932 buf = mr .allocate (1 )
949933 _fill (buf , 0x7E )
950934 queue = mp .Queue ()
951- _run_child (self .child_main , device .device_id , buf , queue )
935+ run_child (self .child_main , device .device_id , buf , queue )
952936 result = queue .get (timeout = CHILD_TIMEOUT_SEC )
953937 assert result ["dl_device" ] == (int (DLDeviceType .kDLCUDA ), device .device_id )
954938 assert result ["shape" ] == (buf .size ,)
0 commit comments