def test_wait_for_interrupted_fired(self): # Test KEVENT_STATUS_FIRED # This is tricky, need two coroutines to be scheduled at the same time, # the first one a normal one and the second one as a result of a kevent # firing (in that specific order). read_fd1, write_fd1 = os.pipe() read_fd2, write_fd2 = os.pipe() try: read_sock1 = coro.sock(fd=read_fd1) read_sock2 = coro.sock(fd=read_fd2) # We're going to have two threads. Since we can't guarantee # which one will show up in kqueue first, we'll just have it # interrupt the other one, and verify that only one ran. sleeper1_thread = None sleeper2_thread = None sleeper1_data = [] sleeper2_data = [] def sleeper1(): data = read_sock1.read(10) sleeper1_data.append(data) sleeper2_thread.shutdown() def sleeper2(): data = read_sock2.read(10) sleeper2_data.append(data) sleeper1_thread.shutdown() sleeper1_thread = coro.spawn(sleeper1) sleeper2_thread = coro.spawn(sleeper2) coro.yield_slice() # Both are waiting, wake them both up. os.write(write_fd1, 'sleeper1') os.write(write_fd2, 'sleeper2') coro.yield_slice() # Yield again to ensure the shutdown runs. coro.yield_slice() self.assertTrue(len(sleeper1_data) == 1 or len(sleeper2_data) == 1) self.assertTrue(sleeper1_thread.dead) self.assertTrue(sleeper2_thread.dead) finally: os.close(read_fd1) os.close(write_fd1) os.close(read_fd2) os.close(write_fd2)
def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None): if _sock is None: self._sock = coro.sock(family, type, proto) else: self._sock = _sock self.family = family self.type = type self.proto = proto self.timeout = _defaulttimeout
def serve(G): path = os.path.join(G.args.base, G.args.file) s = coro.sock(coro.AF.UNIX, coro.SOCK.STREAM) try: os.unlink(path) except OSError: pass s.bind(path) s.listen(100) while 1: conn, addr = s.accept() if coro.fork() == 0: coro.spawn(go, G, conn) s.close() return else: conn.close() coro.set_exit()
def serve (G): path = os.path.join (G.args.base, G.args.file) s = coro.sock (coro.AF.UNIX, coro.SOCK.STREAM) try: os.unlink (path) except OSError: pass s.bind (path) s.listen (100) while 1: conn, addr = s.accept() if coro.fork() == 0: coro.spawn (go, G, conn) s.close() return else: conn.close() coro.set_exit()
def __init__(self, path='/dev/log', facility=16, level=6): self.sock = coro.sock(coro.AF.UNIX, coro.SOCK.DGRAM) self.sock.connect(path) self.encoded = (facility << 3) | level
def fromfd(fd, family, type, proto=0): with _error_converter: fd = os.dup(fd) sock = coro.sock(family, type, proto, fd=fd) return socket(family, type, proto, _sock=sock)
def __init__ (self, path='/dev/log', facility=16, level=6): self.sock = coro.sock (coro.AF.UNIX, coro.SOCK.DGRAM) self.sock.connect (path) self.encoded = (facility << 3) | level