Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProcessPool issue : error: (9, 'Bad file descriptor') #10

Closed
pw717 opened this issue Jun 6, 2017 · 9 comments
Closed

ProcessPool issue : error: (9, 'Bad file descriptor') #10

pw717 opened this issue Jun 6, 2017 · 9 comments

Comments

@pw717
Copy link

pw717 commented Jun 6, 2017

Hello again.
An other issue with the example : (4.2.1 and moc osx 10.12.5).
I cannot go threw the example on https://pypi.python.org/pypi/Pebble, see code below

def function(foo, bar=0):
    return foo + bar

def task_done(future):
    try:
        result = future.result()  # blocks until results are ready
    except Exception as error:
        print("Function raised %s" % error)
        print(error.traceback)  # traceback of the function
    except TimeoutError as error:
        print("Function took longer than %d seconds" % error.args[1])

with ProcessPool(max_workers=5, max_tasks=10) as pool:
    for i in range(0, 10):
        future = pool.schedule(function, args=[i], timeout=3)
        future.add_done_callback(task_done)

It gives at the end of exectution :

Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/site-packages/pebble/pool/process.py", line 155, in message_manager_loop
    pool_manager.process_next_message(SLEEP_UNIT)
  File "/usr/local/lib/python2.7/site-packages/pebble/pool/process.py", line 184, in process_next_message
    message = self.worker_manager.receive(timeout)
  File "/usr/local/lib/python2.7/site-packages/pebble/pool/process.py", line 304, in receive
    if self.pool_channel.poll(timeout):
  File "/usr/local/lib/python2.7/site-packages/pebble/pool/channel.py", line 44, in unix_poll
    return bool(select([self.reader], [], [], timeout)[0])
error: (9, 'Bad file descriptor')

Thank you again in advance for youy help ! :-)

@noxdafox
Copy link
Owner

noxdafox commented Jun 12, 2017

Hi, I'm trying to get my hands on a MAC so I can try to reproduce the issue. I will come back once I succeed.

noxdafox added a commit that referenced this issue Jul 19, 2017
All tests are passing on OSX.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
@noxdafox
Copy link
Owner

Some updates: I did not manage to get a MAC to try to reproduce your issue. Nevertheless, I managed to set up test automation on Travis including OSX OS.

https://travis-ci.org/noxdafox/pebble

All tests are passing successfully. I am pretty confident that the issue you suffer from would have most likely shown itself in the tests as the coverage is pretty good.

This narrows down the issue to your set-up. I wonder what can cause that bad file descriptor.

Are you, by any chance, terminating the Pool workers manually?
Is there any specific constraint within your environment?
Did you limit the amount of file descriptors with ulimit?

@e271828-
Copy link

e271828- commented Jul 21, 2017

@noxdafox I have the same error on a mac when using ProcessPool.

add_done_callback indicates everything completes successfully.

Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/site-packages/pebble/pool/process.py", line 155, in message_manager_loop
    pool_manager.process_next_message(SLEEP_UNIT)
  File "/usr/local/lib/python2.7/site-packages/pebble/pool/process.py", line 184, in process_next_message
    message = self.worker_manager.receive(timeout)
  File "/usr/local/lib/python2.7/site-packages/pebble/pool/process.py", line 304, in receive
    if self.pool_channel.poll(timeout):
  File "/usr/local/lib/python2.7/site-packages/pebble/pool/channel.py", line 44, in unix_poll
    return bool(select([self.reader], [], [], timeout)[0])
error: (9, 'Bad file descriptor')

@noxdafox
Copy link
Owner

noxdafox commented Jul 21, 2017

The traceback indicates that the OS pipe used to communicate with the worker processes gets somehow closed.

Are the tasks completed correctly? If so, this might happen when the ProcessPool is terminated. In such case, this is just noise which I can silence.

Yet I want to make sure this is not affecting the task processing.

@e271828-
Copy link

@noxdafox The tasks are indeed completed correctly. So far as I can tell it's just noise.

noxdafox pushed a commit that referenced this issue Jul 23, 2017
In Python 2, select exception have a custom class.

When shutting down the ProcessPool, the message reader might receive a
select.error which was not handled.

Signed-off-by: cafama <matteo.cafasso@f-secure.com>
noxdafox added a commit that referenced this issue Jul 23, 2017
In Python 2, select exception have a custom class.

When shutting down the ProcessPool, the message reader might receive a
select.error which was not handled.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
@noxdafox
Copy link
Owner

The following branch should fix the issue.

The issue seems to affect only Python 2 and it's due to a custom select exception which was not dealt with during the ProcessPool shutdown. Hence the noisy traceback.

noxdafox added a commit that referenced this issue Jul 24, 2017
issue #10: channel, wrap select.error into OSError
@noxdafox
Copy link
Owner

Patch merged and released in version 4.3.3.

Thanks @e271828- for trying it out.

@pw717
Copy link
Author

pw717 commented Jul 24, 2017

Sorry I arrive late since I was on vacation, but version 4.3.3 is also OK for me on the Mac OSX.
Thank-you very much again for your help and your time !

@noxdafox
Copy link
Owner

Np, thank you for reporting the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants