def test_server_multiproc(set_timeout, restore_signal):
started = mp.Value('i', 0)
terminated = mp.Value('i', 0)
proc_idxs = mp.Array('i', 3)
@aiotools.actxmgr
async def myserver(loop, proc_idx, args):
started, terminated, proc_idxs = args
await asyncio.sleep(0)
with started.get_lock():
started.value += 1
proc_idxs[proc_idx] = proc_idx
yield
await asyncio.sleep(0)
with terminated.get_lock():
terminated.value += 1
def interrupt():
os.kill(0, signal.SIGINT)
set_timeout(0.2, interrupt)
aiotools.start_server(myserver, num_workers=3,
args=(started, terminated, proc_idxs))
assert started.value == 3
assert terminated.value == 3
assert list(proc_idxs) == [0, 1, 2]
assert len(mp.active_children()) == 0
评论列表
文章目录