Using process poll() while using gevent

458 views
Skip to first unread message

Bobby R.

unread,
Aug 1, 2015, 4:09:09 PM8/1/15
to gevent: coroutine-based Python network library
Hello,

I am using a module that requires gevent but as a consequence my existing code that uses subprocess poll() method no longer works. I understand that it is set to False because of gevent.

In short I'm running a subprocess (external command) within a thread that uses process.poll() to check for the existence of that process. Unfortunately it spits out this but still works.

  File "./app.py", line 67, in target
    self.output, self.error = self.process.communicate()
  File "/usr/lib/python2.7/subprocess.py", line 799, in communicate
    return self._communicate(input)
  File "/usr/lib/python2.7/subprocess.py", line 1401, in _communicate
    stdout, stderr = self._communicate_with_poll(input)
  File "/usr/lib/python2.7/subprocess.py", line 1431, in _communicate_with_poll
    poller = select.poll()
AttributeError: 'module' object has no attribute 'poll'

I am unclear on monkey patching and what it does in general but if I add the code below:

from gevent import monkey; monkey.patch_all(subprocess=True)

I no longer see the aforementioned error but poll() no longer works. Is there a way to use both gevent and subprocess poll() within my code?

Or is there another method to poll for whether my subprocess is still running with my thread?

Thanks

Jason Madden

unread,
Aug 3, 2015, 7:45:36 AM8/3/15
to gevent: coroutine-based Python network library
You may find the discussion in issue 446 to be relevant (and in particular this comment summarizes the fixes). In short, in a fully and properly monkey-patched system, subprocess.Popen.poll works as expected; the trick is just to monkey patch in the correct order at the correct time.

You may also try upgrading to gevent 1.1b1 which fixes the problem in a different way; see the changelog for details.
Reply all
Reply to author
Forward
0 new messages