From e544b4ea63275bbaf31f305133b7a931def983cf Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Wed, 29 Apr 2015 23:00:17 +0100 Subject: [PATCH] sloppy --- celery/concurrency/asynpool.py | 6 ++--- celery/tests/concurrency/test_prefork.py | 34 ++++++++++++------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/celery/concurrency/asynpool.py b/celery/concurrency/asynpool.py index 501707f06cc..b1cb64751c5 100644 --- a/celery/concurrency/asynpool.py +++ b/celery/concurrency/asynpool.py @@ -110,7 +110,7 @@ def _get_job_writer(job): return writer() # is a weakref -if hasattr(select, 'poll', None): +if hasattr(select, 'poll'): def _select_imp(readers=None, writers=None, err=None, timeout=0, poll=select.poll, POLLIN=select.POLLIN, POLLOUT=select.POLLOUT, POLLERR=select.POLLERR): @@ -146,7 +146,7 @@ def _select_imp(readers=None, writers=None, err=None, timeout=0): def _select(readers=None, writers=None, err=None, timeout=0, - _select_imp=_select_imp): + poll=_select_imp): """Simple wrapper to :class:`~select.select`, using :`~select.poll` as the implementation. @@ -170,7 +170,7 @@ def _select(readers=None, writers=None, err=None, timeout=0, writers = set() if writers is None else writers err = set() if err is None else err try: - return _select_imp(readers, writers, err, timeout) + return poll(readers, writers, err, timeout) except (select.error, socket.error) as exc: if exc.errno == errno.EINTR: return set(), set(), 1 diff --git a/celery/tests/concurrency/test_prefork.py b/celery/tests/concurrency/test_prefork.py index 00fec85d9c0..23c35ad0bac 100644 --- a/celery/tests/concurrency/test_prefork.py +++ b/celery/tests/concurrency/test_prefork.py @@ -154,46 +154,46 @@ def test_select(self, __select): ebadf.errno = errno.EBADF with patch('select.poll', create=True) as poller: poll = poller.return_value = Mock(name='poll.poll') - poll.poll.return_value = [(3, select.POLLIN)] + poll.return_value = {3}, set(), 0 self.assertEqual( - asynpool._select({3}, poll=poller), + asynpool._select({3}, poll=poll), ({3}, set(), 0), ) - poll.poll.return_value = [(3, select.POLLERR)] + poll.return_value = {3}, set(), 0 self.assertEqual( - asynpool._select({3}, None, {3}, poll=poller), + asynpool._select({3}, None, {3}, poll=poll), ({3}, set(), 0), ) eintr = socket.error() eintr.errno = errno.EINTR - poll.poll.side_effect = eintr + poll.side_effect = eintr readers = {3} self.assertEqual( - asynpool._select(readers, poll=poller), + asynpool._select(readers, poll=poll), (set(), set(), 1), ) self.assertIn(3, readers) with patch('select.poll') as poller: poll = poller.return_value = Mock(name='poll.poll') - poll.poll.side_effect = ebadf + poll.side_effect = ebadf with patch('select.select') as selcheck: selcheck.side_effect = ebadf readers = {3} self.assertEqual( - asynpool._select(readers, poll=poller), + asynpool._select(readers, poll=poll), (set(), set(), 1), ) self.assertNotIn(3, readers) with patch('select.poll') as poller: poll = poller.return_value = Mock(name='poll.poll') - poll.poll.side_effect = MemoryError() + poll.side_effect = MemoryError() with self.assertRaises(MemoryError): - asynpool._select({1}, poll=poller) + asynpool._select({1}, poll=poll) with patch('select.poll') as poller: poll = poller.return_value = Mock(name='poll.poll') @@ -202,9 +202,9 @@ def test_select(self, __select): def se(*args): selcheck.side_effect = MemoryError() raise ebadf - poll.poll.side_effect = se + poll.side_effect = se with self.assertRaises(MemoryError): - asynpool._select({3}, poll=poller) + asynpool._select({3}, poll=poll) with patch('select.poll') as poller: poll = poller.return_value = Mock(name='poll.poll') @@ -214,17 +214,17 @@ def se2(*args): selcheck.side_effect = socket.error() selcheck.side_effect.errno = 1321 raise ebadf - poll.poll.side_effect = se2 + poll.side_effect = se2 with self.assertRaises(socket.error): - asynpool._select({3}, poll=poller) + asynpool._select({3}, poll=poll) with patch('select.poll') as poller: poll = poller.return_value = Mock(name='poll.poll') - poll.poll.side_effect = socket.error() - poll.poll.side_effect.errno = 34134 + poll.side_effect = socket.error() + poll.side_effect.errno = 34134 with self.assertRaises(socket.error): - asynpool._select({3}, poll=poller) + asynpool._select({3}, poll=poll) def test_promise(self): fun = Mock()