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

Class TestThreadedServer

Lib/test/test_asyncio/test_ssl.py:1819–1897  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1817
1818
1819class TestThreadedServer(SocketThread):
1820
1821 def __init__(self, test, sock, prog, timeout, max_clients):
1822 threading.Thread.__init__(self, None, None, 'test-server')
1823 self.daemon = True
1824
1825 self._clients = 0
1826 self._finished_clients = 0
1827 self._max_clients = max_clients
1828 self._timeout = timeout
1829 self._sock = sock
1830 self._active = True
1831
1832 self._prog = prog
1833
1834 self._s1, self._s2 = socket.socketpair()
1835 self._s1.setblocking(False)
1836
1837 self._test = test
1838
1839 def stop(self):
1840 try:
1841 if self._s2 and self._s2.fileno() != -1:
1842 try:
1843 self._s2.send(b'stop')
1844 except OSError:
1845 pass
1846 finally:
1847 super().stop()
1848 self._sock.close()
1849 self._s1.close()
1850 self._s2.close()
1851
1852 def run(self):
1853 self._sock.setblocking(False)
1854 self._run()
1855
1856 def _run(self):
1857 while self._active:
1858 if self._clients >= self._max_clients:
1859 return
1860
1861 r, w, x = select.select(
1862 [self._sock, self._s1], [], [], self._timeout)
1863
1864 if self._s1 in r:
1865 return
1866
1867 if self._sock in r:
1868 try:
1869 conn, addr = self._sock.accept()
1870 except BlockingIOError:
1871 continue
1872 except socket.timeout:
1873 if not self._active:
1874 return
1875 else:
1876 raise

Callers 1

tcp_serverMethod · 0.70

Calls

no outgoing calls

Tested by 1

tcp_serverMethod · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…