@@ -3513,14 +3513,82 @@ def test_lock(self):
35133513 p .join ()
35143514 self .assertLessEqual (new_size , old_size )
35153515
3516+ #
3517+ # Issue #17097: EINTR should be ignored by recv(), send(), accept() etc
3518+ #
3519+
3520+ class TestIgnoreEINTR (unittest .TestCase ):
3521+
3522+ @classmethod
3523+ def _test_ignore (cls , conn ):
3524+ def handler (signum , frame ):
3525+ pass
3526+ signal .signal (signal .SIGUSR1 , handler )
3527+ conn .send ('ready' )
3528+ x = conn .recv ()
3529+ conn .send (x )
3530+ conn .send_bytes (b'x' * (1024 * 1024 )) # sending 1 MB should block
3531+
3532+ @unittest .skipUnless (hasattr (signal , 'SIGUSR1' ), 'requires SIGUSR1' )
3533+ def test_ignore (self ):
3534+ conn , child_conn = multiprocessing .Pipe ()
3535+ try :
3536+ p = multiprocessing .Process (target = self ._test_ignore ,
3537+ args = (child_conn ,))
3538+ p .daemon = True
3539+ p .start ()
3540+ child_conn .close ()
3541+ self .assertEqual (conn .recv (), 'ready' )
3542+ time .sleep (0.1 )
3543+ os .kill (p .pid , signal .SIGUSR1 )
3544+ time .sleep (0.1 )
3545+ conn .send (1234 )
3546+ self .assertEqual (conn .recv (), 1234 )
3547+ time .sleep (0.1 )
3548+ os .kill (p .pid , signal .SIGUSR1 )
3549+ self .assertEqual (conn .recv_bytes (), b'x' * (1024 * 1024 ))
3550+ time .sleep (0.1 )
3551+ p .join ()
3552+ finally :
3553+ conn .close ()
3554+
3555+ @classmethod
3556+ def _test_ignore_listener (cls , conn ):
3557+ def handler (signum , frame ):
3558+ pass
3559+ signal .signal (signal .SIGUSR1 , handler )
3560+ l = multiprocessing .connection .Listener ()
3561+ conn .send (l .address )
3562+ a = l .accept ()
3563+ a .send ('welcome' )
3564+
3565+ @unittest .skipUnless (hasattr (signal , 'SIGUSR1' ), 'requires SIGUSR1' )
3566+ def test_ignore_listener (self ):
3567+ conn , child_conn = multiprocessing .Pipe ()
3568+ try :
3569+ p = multiprocessing .Process (target = self ._test_ignore_listener ,
3570+ args = (child_conn ,))
3571+ p .daemon = True
3572+ p .start ()
3573+ child_conn .close ()
3574+ address = conn .recv ()
3575+ time .sleep (0.1 )
3576+ os .kill (p .pid , signal .SIGUSR1 )
3577+ time .sleep (0.1 )
3578+ client = multiprocessing .connection .Client (address )
3579+ self .assertEqual (client .recv (), 'welcome' )
3580+ p .join ()
3581+ finally :
3582+ conn .close ()
3583+
35163584#
35173585#
35183586#
35193587
35203588testcases_other = [OtherTest , TestInvalidHandle , TestInitializers ,
35213589 TestStdinBadfiledescriptor , TestWait , TestInvalidFamily ,
35223590 TestFlags , TestTimeouts , TestNoForkBomb ,
3523- TestForkAwareThreadLock ]
3591+ TestForkAwareThreadLock , TestIgnoreEINTR ]
35243592
35253593#
35263594#
0 commit comments