MCPcopy Index your code
hub / github.com/python/cpython / check_sendall_interrupted

Method check_sendall_interrupted

Lib/test/test_socket.py:1834–1863  ·  view source on GitHub ↗
(self, with_timeout)

Source from the content-addressed store, hash-verified

1832 # socket.gethostbyaddr('испытание.python.org')
1833
1834 def check_sendall_interrupted(self, with_timeout):
1835 # socketpair() is not strictly required, but it makes things easier.
1836 if not hasattr(signal, 'alarm') or not hasattr(socket, 'socketpair'):
1837 self.skipTest("signal.alarm and socket.socketpair required for this test")
1838 # Our signal handlers clobber the C errno by calling a math function
1839 # with an invalid domain value.
1840 def ok_handler(*args):
1841 self.assertRaises(ValueError, math.acosh, 0)
1842 def raising_handler(*args):
1843 self.assertRaises(ValueError, math.acosh, 0)
1844 1 // 0
1845 c, s = socket.socketpair()
1846 old_alarm = signal.signal(signal.SIGALRM, raising_handler)
1847 try:
1848 if with_timeout:
1849 # Just above the one second minimum for signal.alarm
1850 c.settimeout(1.5)
1851 with self.assertRaises(ZeroDivisionError):
1852 signal.alarm(1)
1853 c.sendall(b"x" * support.SOCK_MAX_SIZE)
1854 if with_timeout:
1855 signal.signal(signal.SIGALRM, ok_handler)
1856 signal.alarm(1)
1857 self.assertRaises(TimeoutError, c.sendall,
1858 b"x" * support.SOCK_MAX_SIZE)
1859 finally:
1860 signal.alarm(0)
1861 signal.signal(signal.SIGALRM, old_alarm)
1862 c.close()
1863 s.close()
1864
1865 def test_sendall_interrupted(self):
1866 self.check_sendall_interrupted(False)

Calls 6

skipTestMethod · 0.80
socketpairMethod · 0.45
settimeoutMethod · 0.45
assertRaisesMethod · 0.45
sendallMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected