I have a celery worker consisting of a task to run puppet agent on a remote machine which is a blocking call. I also have other http api flows in other tasks that can benefit from eventlet
@app.task(soft_time_limit=600)
def run_puppet_agent(hostname):
try:
env.host_string = self.host
env.user = self.username
env.password = self.password
return sudo('puppet agent -t')
except SoftTimeLimitExceeded:
raise Exception('Puppet agent TIMED OUT AFTER 600 seconds')
except Exception as e:
#run_puppet_agent.retry(args=[hostname], countdown=20)
LOG.info('')
raise Exception('Puppet agent failed with error message %s' % e.message)
When I run the worker as
celery multi start 2 -A phantom.celery.manage -P eventlet -c 15 --loglevel=INFO
It gives me an exception trace like follows:
Traceback (most recent call last):
File "/home/uruddarraju/Phantom/phantom/tasks/fabric_tasks.py", line 19, in run_puppet_agent
return sudo(command, quiet=False)
File "/home/uruddarraju/Phantom/tools/virtualenv/local/lib/python2.7/site-packages/fabric/network.py", line 639, in host_prompting_wrapper
return func(*args, **kwargs)
File "/home/uruddarraju/Phantom/tools/virtualenv/local/lib/python2.7/site-packages/fabric/operations.py", line 1095, in sudo
stderr=stderr, timeout=timeout, shell_escape=shell_escape,
File "/home/uruddarraju/Phantom/tools/virtualenv/local/lib/python2.7/site-packages/fabric/operations.py", line 911, in _run_command
stderr=stderr, timeout=timeout)
File "/home/uruddarraju/Phantom/tools/virtualenv/local/lib/python2.7/site-packages/fabric/operations.py", line 795, in _execute
worker.raise_if_needed()
File "/home/uruddarraju/Phantom/tools/virtualenv/local/lib/python2.7/site-packages/fabric/thread_handling.py", line 12, in wrapper
callable(*args, **kwargs)
File "/home/uruddarraju/Phantom/tools/virtualenv/local/lib/python2.7/site-packages/fabric/io.py", line 231, in input_loop
r, w, x = select([sys.stdin], [], [], 0.0)
File "/home/uruddarraju/Phantom/tools/virtualenv/local/lib/python2.7/site-packages/eventlet/green/select.py", line 79, in select
listeners.append(hub.add(hub.READ, k, on_read))
File "/home/uruddarraju/Phantom/tools/virtualenv/local/lib/python2.7/site-packages/eventlet/hubs/epolls.py", line 52, in add
self.register(fileno, new=True)
File "/home/uruddarraju/Phantom/tools/virtualenv/local/lib/python2.7/site-packages/eventlet/hubs/poll.py", line 45, in register
self.poll.register(fileno, mask)
IOError: [Errno 1] Operation not permitted
I have read: Why does select.select() work with disk files but not epoll()? and see that there is a problem having eventlet working with fabric or such blocking calls. Is there a way I can tell celery not to monkey patch this particular task ?
This error was mitigated when I used gevent instead. I hope it enables the same performance for me.