Reputation: 93
Starting with one of the two examples from the User Guide ( https://aiomultiprocess.omnilib.dev/en/latest/guide.html ) I started my testing with an own variation:
import asyncio
import psutil
import multiprocessing
from aiomultiprocess import Worker
from time import sleep
def check_process_count():
python_procs = [p for p in psutil.process_iter(attrs=["pid", "name"]) if "python" in p.info["name"]]
print(f"Active Python-Processes: {[p.info['pid'] for p in python_procs]}")
async def wait():
print('Wait 5')
sleep(5.0)
return('123')
async def program1():
check_process_count()
myprocess = Worker(target=wait, )
check_process_count()
print('myprocess = Worker(target=wait, )')
myprocess.start()
print('myprocess.start()')
check_process_count()
print(await myprocess.join())
print('await myprocess.join()')
if __name__ == "__main__":
asyncio.run(program1())
The output of this test program shows that it generates two new processes:
(test) ludger@lhnotebook:~/safe/sources/python/test$ python test.py
Active Python-Processes: [7585]
Active Python-Processes: [7585, 7586]
myprocess = Worker(target=wait, )
myprocess.start()
Wait 5
Active Python-Processes: [7585, 7586, 7592]
123
await myprocess.join()
The first one is generated when Worker initializes, which should not be the case according to the documentation. The second one shows up ẃith the start, which is OK. Where is my misunderstanding?
Upvotes: 1
Views: 18
Reputation: 93
I found it looking into /multiprocessing/context.py: The process started first is the SyncManager that enables sharing of Queues etc. between the Processes. So, nothing to worry about...
Upvotes: 1