@@ -3460,14 +3460,82 @@ def test_lock(self):
34603460 p .join ()
34613461 self .assertLessEqual (new_size , old_size )
34623462
3463+ #
3464+ # Issue #17097: EINTR should be ignored by recv(), send(), accept() etc
3465+ #
3466+
3467+ class TestIgnoreEINTR (unittest .TestCase ):
3468+
3469+ @classmethod
3470+ def _test_ignore (cls , conn ):
3471+ def handler (signum , frame ):
3472+ pass
3473+ signal .signal (signal .SIGUSR1 , handler )
3474+ conn .send ('ready' )
3475+ x = conn .recv ()
3476+ conn .send (x )
3477+ conn .send_bytes (b'x' * (1024 * 1024 )) # sending 1 MB should block
3478+
3479+ @unittest .skipUnless (hasattr (signal , 'SIGUSR1' ), 'requires SIGUSR1' )
3480+ def test_ignore (self ):
3481+ conn , child_conn = multiprocessing .Pipe ()
3482+ try :
3483+ p = multiprocessing .Process (target = self ._test_ignore ,
3484+ args = (child_conn ,))
3485+ p .daemon = True
3486+ p .start ()
3487+ child_conn .close ()
3488+ self .assertEqual (conn .recv (), 'ready' )
3489+ time .sleep (0.1 )
3490+ os .kill (p .pid , signal .SIGUSR1 )
3491+ time .sleep (0.1 )
3492+ conn .send (1234 )
3493+ self .assertEqual (conn .recv (), 1234 )
3494+ time .sleep (0.1 )
3495+ os .kill (p .pid , signal .SIGUSR1 )
3496+ self .assertEqual (conn .recv_bytes (), b'x' * (1024 * 1024 ))
3497+ time .sleep (0.1 )
3498+ p .join ()
3499+ finally :
3500+ conn .close ()
3501+
3502+ @classmethod
3503+ def _test_ignore_listener (cls , conn ):
3504+ def handler (signum , frame ):
3505+ pass
3506+ signal .signal (signal .SIGUSR1 , handler )
3507+ l = multiprocessing .connection .Listener ()
3508+ conn .send (l .address )
3509+ a = l .accept ()
3510+ a .send ('welcome' )
3511+
3512+ @unittest .skipUnless (hasattr (signal , 'SIGUSR1' ), 'requires SIGUSR1' )
3513+ def test_ignore_listener (self ):
3514+ conn , child_conn = multiprocessing .Pipe ()
3515+ try :
3516+ p = multiprocessing .Process (target = self ._test_ignore_listener ,
3517+ args = (child_conn ,))
3518+ p .daemon = True
3519+ p .start ()
3520+ child_conn .close ()
3521+ address = conn .recv ()
3522+ time .sleep (0.1 )
3523+ os .kill (p .pid , signal .SIGUSR1 )
3524+ time .sleep (0.1 )
3525+ client = multiprocessing .connection .Client (address )
3526+ self .assertEqual (client .recv (), 'welcome' )
3527+ p .join ()
3528+ finally :
3529+ conn .close ()
3530+
34633531#
34643532#
34653533#
34663534
34673535testcases_other = [OtherTest , TestInvalidHandle , TestInitializers ,
34683536 TestStdinBadfiledescriptor , TestWait , TestInvalidFamily ,
34693537 TestFlags , TestTimeouts , TestNoForkBomb ,
3470- TestForkAwareThreadLock ]
3538+ TestForkAwareThreadLock , TestIgnoreEINTR ]
34713539
34723540#
34733541#
0 commit comments