# another option besides sleep(1) in async\_wrapper

**URL:** <https://forum.ansible.com/t/another-option-besides-sleep-1-in-async-wrapper/20471>\
**Category:** Ansible Developer\
**Tags:** aws\
**Created:** [February 5, 2016, 11:24pm UTC](https://forum.ansible.com/t/another-option-besides-sleep-1-in-async-wrapper/20471 "2016-02-05T23:24:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Casey\_Lucas](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@Casey\_Lucas](https://forum.ansible.com/u/Casey_Lucas)\
**Post date:** [February 5, 2016, 11:24pm UTC](https://forum.ansible.com/t/another-option-besides-sleep-1-in-async-wrapper/20471/1 "2016-02-05T23:24:25Z")

</div>

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](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](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
