async def test_set_start_method(self): with self.assertRaises(ValueError): amp.set_start_method("foo") if sys.platform.startswith("win32"): amp.set_start_method(None) self.assertEqual(amp.core.get_context().get_start_method(), "spawn") with self.assertRaises(ValueError): amp.set_start_method("fork") elif sys.platform.startswith("linux") or sys.platform.startswith("darwin"): amp.set_start_method("fork") async def inline(x): return x result = await amp.Worker(target=inline, args=(17,), name="test_inline") self.assertEqual(result, 17)
import asyncio from aiomultiprocess import Process, Worker import aiomultiprocess import os aiomultiprocess.set_start_method('fork') async def do_sleep(): while True: print(os.getpid()) await asyncio.sleep(1) async def create_process(): p = Process(target=do_sleep) p.start() #import pdb; pdb.set_trace() # p.terminate() # here works return p async def main(): p = await create_process() #p.terminate() if __name__ == "__main__": asyncio.run(main())
def setUp(self): # reset to default context before each test amp.set_start_method()