I run some tasks asynchronously (localhost against AWS) and noticed that the start time of a list of tasks (using with_item) is always pretty much equal to the number of items in the list times 1 second. This startup time is normally no big deal unless you have a lot of items in the list. I noticed that in async_wrapper.py there is a sleep(1) (https://github.com/ansible/ansible-modules-core/blob/devel/utilities/logic/async_wrapper.py#L156). After looking at the code and the comments above I think I understand the purpose of the sleep.
I was wondering if the sleep could be removed. In order to remove the sleep, the descendant process that is executing inside of _run_module would need to be able to communicate back to the original process after it creates the original jobfile (https://github.com/ansible/ansible-modules-core/blob/devel/utilities/logic/async_wrapper.py#L79). Additionally, the files that are referenced in the wrapped_cmd parameter to _run_module ((1) module python code and (2) arguments file)) would need to be moved out of their original directory because ansible does an rm -f -r on the directory as soon as the original process returns.
I verified that the IPC can be done with os.pipe. Is it a reasonable strategy to create a directory under ~/.ansible_async/ (for example ~/.ansible_async/jid.tmp) and move the two files there? I think the async_status module would also need to remove the jid.tmp directory when run in cleanup mode. I don’t know if there are other implications to moving the two files there though. Any thoughts/suggestions welcome.
I can submit a PR if the strategy seems ok.
Thanks,
Casey