# writing a an ansible module - seems that Popen is spending a long time polling

**URL:** <https://forum.ansible.com/t/writing-a-an-ansible-module-seems-that-popen-is-spending-a-long-time-polling/16534>\
**Category:** Ansible Developer\
**Tags:** ubuntu\
**Created:** [October 16, 2014, 10:46pm UTC](https://forum.ansible.com/t/writing-a-an-ansible-module-seems-that-popen-is-spending-a-long-time-polling/16534 "2014-10-16T22:46:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bryan\_Hunt](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@Bryan\_Hunt](https://forum.ansible.com/u/Bryan_Hunt)\
**Post date:** [October 16, 2014, 10:46pm UTC](https://forum.ansible.com/t/writing-a-an-ansible-module-seems-that-popen-is-spending-a-long-time-polling/16534/1 "2014-10-16T22:46:32Z")

</div>

Hello all,

Perhaps this is a general Python question, if so, I apologize in advance for having had the temerity to ask it here.

One of our team was complaining that the Riak stuff was slow. Now this is always a subjective thing, and I think Ansible is fast, so I hacked the Riak module and added in some cProfile stuff so I could profile the main() block.

( All the links for running this are at [https://gist.github.com/binarytemple/5ccbe8f3325b4113c432](https://gist.github.com/binarytemple/5ccbe8f3325b4113c432) )

I then ran it against a 3 node Vagrant cluster running on my laptop (vagrant provision), I wrote the change in such a way that every time the riak module was run, it dumped a file with profiling information to the /tmp directory, then I pulled them all down, concatenated them and took a look a the results.

To cut a long story short, there wasn’t a lot of exciting stuff in there, everything seemed to be fairly quick, apart from what seemed a long time spent polling.

1 module params = {‘target\_node’: ‘riak@127.0.0.1’, ‘config\_dir’: ‘/etc/riak’, ‘wait\_for\_service’: ‘kv’, ‘http\_conn’: ‘127.0.0.1:8098’, ‘wait\_for\_ring’: False, ‘wait\_for\_han doffs’: False, ‘command’: None, ‘validate\_certs’: True}  
2 4232 function calls (4095 primitive calls) in 10.723 seconds  
3  
4 Ordered by: cumulative time  
5  
6 ncalls tottime percall cumtime percall filename:lineno(function)  
7 1 0.000 0.000 10.721 10.721 /home/vagrant/.ansible/tmp/ansible-tmp-1413495802.29-66831348941533/riak:115(maind)  
8 3 0.000 0.000 10.626 3.542 /home/vagrant/.ansible/tmp/ansible-tmp-1413495802.29-66831348941533/riak:1404(run\_command)  
9 3 0.000 0.000 10.613 3.538 /usr/lib/python2.7/subprocess.py:723(communicate)  
10 3 0.000 0.000 10.613 3.538 /usr/lib/python2.7/subprocess.py:1303(\_communicate)  
11 3 0.000 0.000 10.612 3.537 /usr/lib/python2.7/subprocess.py:1336(\_communicate\_with\_poll)  
12 9 10.612 1.179 10.612 1.179 {built-in method poll}  
13 1 0.000 0.000 0.397 0.397 /home/vagrant/.ansible/tmp/ansible-tmp-1413495802.29-66831348941533/riak:107(ring\_check)  
14 1 0.000 0.000 0.094 0.094 /home/vagrant/.ansible/tmp/ansible-tmp-1413495802.29-66831348941533/riak:1836(fetch\_url)

The ring\_check command, which runs under a second on the command line, or in a sample python script which uses Popen to execute, seems to be under this ‘built-in method poll’ which takes 10 seconds.

Has Python spending 10 seconds polling a command which takes less than a second to run?

This box is old, Ubuntu 12.04, Python 2.7.

Bryan Hunt

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [October 20, 2014, 9:36pm UTC](https://forum.ansible.com/t/writing-a-an-ansible-module-seems-that-popen-is-spending-a-long-time-polling/16534/2 "2014-10-20T21:36:40Z")

</div>

I don’t know the answer to this one.

Possibly there’s a process that was slow in closing a file descriptor (or something similar) in the riak stuff?
