Skip to content

Instantly share code, notes, and snippets.

@mattbennett
Created May 19, 2016 15:55
Show Gist options
  • Save mattbennett/0267cce4f0ea365a7f0dacdf68f3eafc to your computer and use it in GitHub Desktop.
Save mattbennett/0267cce4f0ea365a7f0dacdf68f3eafc to your computer and use it in GitHub Desktop.
pytest and eventlet combination hanging on os x
import eventlet
eventlet.monkey_patch()
def pytest_configure(config):
import logging
logging.basicConfig(level=logging.DEBUG) # or comment out this line, works fine
eventlet==0.19.0
pytest==2.9.1
pytest_plugins = "pytester"
def test_bar(testdir):
testdir.makepyfile(
"""
def test_baz():
import logging
log = logging.getLogger()
log.debug("hello") # comment out this line, works fine
assert "foo" == "foo"
"""
)
result = testdir.runpytest()
assert result.ret == 0
@mattbennett
Copy link
Author

mattbennett commented May 19, 2016

pip install -r requirements.txt

Then:

On OS X:

(tmp-9c7a24a0f83a26e9)Matts-13-inch-Macbook-Pro:0267cce4f0ea365a7f0dacdf68f3eafc mattbennett$ py.test test_foo.py
====================================================================================== test session starts =======================================================================================
platform darwin -- Python 3.4.3, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: /Users/mattbennett/.virtualenvs/tmp-9c7a24a0f83a26e9/0267cce4f0ea365a7f0dacdf68f3eafc, inifile:
collected 1 items

test_foo.py

On Debian Jessie (in docker):

(temp) root@3c4ec1bd3773:/var/osl/0267cce4f0ea365a7f0dacdf68f3eafc# py.test test_foo.py
=============================================================================================================================== test session starts ================================================================================================================================
platform linux -- Python 3.4.2, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: /var/osl/0267cce4f0ea365a7f0dacdf68f3eafc, inifile:
collected 1 items

test_foo.py F

===================================================================================================================================== FAILURES =====================================================================================================================================
_____________________________________________________________________________________________________________________________________ test_bar _____________________________________________________________________________________________________________________________________

testdir = <Testdir local('/tmp/pytest-of-root/pytest-8/testdir/test_bar0')>

    def test_bar(testdir):

        testdir.makepyfile(
            """
            def test_baz():
                import logging
                log = logging.getLogger()
                log.debug("hello")  # comment out this line, works fine

                assert "foo" == "foo"
            """
        )
        result = testdir.runpytest()
>       assert result.ret == 0
E       assert 3 == 0
E        +  where 3 = <_pytest.pytester.RunResult object at 0x7fd9430bb2b0>.ret

/var/osl/0267cce4f0ea365a7f0dacdf68f3eafc/test_foo.py:17: AssertionError
------------------------------------------------------------------------------------------------------------------------------- Captured stdout call -------------------------------------------------------------------------------------------------------------------------------
============================= test session starts ==============================
platform linux -- Python 3.4.2, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: /tmp/pytest-of-root/pytest-8/testdir/test_bar0, inifile:
collected 1 items

test_bar.py FE

==================================== ERRORS ====================================
________________________ ERROR at teardown of test_baz _________________________

self = <eventlet.greenio.py3.GreenFileIO object at 0x7fd9430b03c8>, size = -1

    def read(self, size=-1):
        if size == -1:
>           return self.readall()

/var/osl/temp/lib/python3.4/site-packages/eventlet/greenio/py3.py:80:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/var/osl/temp/lib/python3.4/site-packages/eventlet/greenio/py3.py:101: in readall
    self._trampoline(self, read=True)
/var/osl/temp/lib/python3.4/site-packages/eventlet/greenio/py3.py:123: in _trampoline
    mark_as_closed=self._mark_as_closed)
/var/osl/temp/lib/python3.4/site-packages/eventlet/hubs/__init__.py:158: in trampoline
    listener = hub.add(hub.READ, fileno, current.switch, current.throw, mark_as_closed)
/var/osl/temp/lib/python3.4/site-packages/eventlet/hubs/epolls.py:49: in add
    listener = BaseHub.add(self, evtype, fileno, cb, tb, mac)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <eventlet.hubs.epolls.Hub object at 0x7fd943089358>, evtype = 'read'
fileno = 17
cb = <built-in method switch of greenlet.greenlet object at 0x7fd9440ff470>
tb = <built-in method throw of greenlet.greenlet object at 0x7fd9440ff470>
mark_as_closed = <bound method GreenFileIO._mark_as_closed of <eventlet.greenio.py3.GreenFileIO object at 0x7fd9430b03c8>>

    def add(self, evtype, fileno, cb, tb, mark_as_closed):
        """ Signals an intent to or write a particular file descriptor.

            The *evtype* argument is either the constant READ or WRITE.

            The *fileno* argument is the file number of the file of interest.

            The *cb* argument is the callback which will be called when the file
            is ready for reading/writing.

            The *tb* argument is the throwback used to signal (into the greenlet)
            that the file was closed.

            The *mark_as_closed* is used in the context of the event hub to
            prepare a Python object as being closed, pre-empting further
            close operations from accidentally shutting down the wrong OS thread.
            """
        listener = self.lclass(evtype, fileno, cb, tb, mark_as_closed)
        bucket = self.listeners[evtype]
        if fileno in bucket:
            if g_prevent_multiple_readers:
                raise RuntimeError(
                    "Second simultaneous %s on fileno %s "
                    "detected.  Unless you really know what you're doing, "
                    "make sure that only one greenthread can %s any "
                    "particular socket.  Consider using a pools.Pool. "
                    "If you do know what you're doing and want to disable "
                    "this error, call "
                    "eventlet.debug.hub_prevent_multiple_readers(False) - MY THREAD=%s; "
                    "THAT THREAD=%s" % (
>                       evtype, fileno, evtype, cb, bucket[fileno]))
E               RuntimeError: Second simultaneous read on fileno 17 detected.  Unless you really know what you're doing, make sure that only one greenthread can read any particular socket.  Consider using a pools.Pool. If you do know what you're doing and want to disable this error, call eventlet.debug.hub_prevent_multiple_readers(False) - MY THREAD=<built-in method switch of greenlet.greenlet object at 0x7fd9440ff470>; THAT THREAD=FdListener('read', 17, <built-in method switch of greenlet.greenlet object at 0x7fd9440ff470>, <built-in method throw of greenlet.greenlet object at 0x7fd9440ff470>)

/var/osl/temp/lib/python3.4/site-packages/eventlet/hubs/hub.py:177: RuntimeError
=================================== FAILURES ===================================
___________________________________ test_baz ___________________________________

self = <eventlet.greenio.py3.GreenFileIO object at 0x7fd9430b03c8>, size = -1

    def read(self, size=-1):
        if size == -1:
>           return self.readall()

/var/osl/temp/lib/python3.4/site-packages/eventlet/greenio/py3.py:80:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/var/osl/temp/lib/python3.4/site-packages/eventlet/greenio/py3.py:101: in readall
    self._trampoline(self, read=True)
/var/osl/temp/lib/python3.4/site-packages/eventlet/greenio/py3.py:123: in _trampoline
    mark_as_closed=self._mark_as_closed)
/var/osl/temp/lib/python3.4/site-packages/eventlet/hubs/__init__.py:158: in trampoline
    listener = hub.add(hub.READ, fileno, current.switch, current.throw, mark_as_closed)
/var/osl/temp/lib/python3.4/site-packages/eventlet/hubs/epolls.py:53: in add
    self.register(fileno, new=True)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <eventlet.hubs.epolls.Hub object at 0x7fd943089358>, fileno = 17
new = True

    def register(self, fileno, new=False):
        mask = 0
        if self.listeners[READ].get(fileno):
            mask |= READ_MASK | EXC_MASK
        if self.listeners[WRITE].get(fileno):
            mask |= WRITE_MASK | EXC_MASK
        try:
            if mask:
                if new:
>                   self.poll.register(fileno, mask)
E                   PermissionError: [Errno 1] Operation not permitted

/var/osl/temp/lib/python3.4/site-packages/eventlet/hubs/poll.py:45: PermissionError
====================== 1 failed, 1 error in 0.06 seconds =======================
------------------------------------------------------------------------------------------------------------------------------- Captured stderr call -------------------------------------------------------------------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/osl/temp/lib/python3.4/site-packages/_pytest/pytester.py", line 719, in runpytest_inprocess
    reprec = self.inline_run(*args, **kwargs)
  File "/var/osl/temp/lib/python3.4/site-packages/_pytest/pytester.py", line 693, in inline_run
    ret = pytest.main(list(args), plugins=plugins)
  File "/var/osl/temp/lib/python3.4/site-packages/_pytest/config.py", line 49, in main
    return config.hook.pytest_cmdline_main(config=config)
  File "/var/osl/temp/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 724, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/var/osl/temp/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 338, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/var/osl/temp/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 333, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/var/osl/temp/lib/python3.4/site-packages/_pytest/vendored_packages/pluggy.py", line 596, in execute
    res = hook_impl.function(*args)
  File "/var/osl/temp/lib/python3.4/site-packages/_pytest/main.py", line 119, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/var/osl/temp/lib/python3.4/site-packages/_pytest/main.py", line 115, in wrap_session
    config._ensure_unconfigure()
  File "/var/osl/temp/lib/python3.4/site-packages/_pytest/config.py", line 848, in _ensure_unconfigure
    fin()
  File "/var/osl/temp/lib/python3.4/site-packages/_pytest/capture.py", line 80, in reset_capturings
    cap.pop_outerr_to_orig()
  File "/var/osl/temp/lib/python3.4/site-packages/_pytest/capture.py", line 263, in pop_outerr_to_orig
    out, err = self.readouterr()
  File "/var/osl/temp/lib/python3.4/site-packages/_pytest/capture.py", line 303, in readouterr
    self.err.snap() if self.err is not None else "")
  File "/var/osl/temp/lib/python3.4/site-packages/_pytest/capture.py", line 350, in snap
    res = f.read()
  File "/var/osl/temp/lib/python3.4/site-packages/eventlet/greenio/py3.py", line 80, in read
    return self.readall()
  File "/var/osl/temp/lib/python3.4/site-packages/eventlet/greenio/py3.py", line 101, in readall
    self._trampoline(self, read=True)
  File "/var/osl/temp/lib/python3.4/site-packages/eventlet/greenio/py3.py", line 123, in _trampoline
    mark_as_closed=self._mark_as_closed)
  File "/var/osl/temp/lib/python3.4/site-packages/eventlet/hubs/__init__.py", line 158, in trampoline
    listener = hub.add(hub.READ, fileno, current.switch, current.throw, mark_as_closed)
  File "/var/osl/temp/lib/python3.4/site-packages/eventlet/hubs/epolls.py", line 49, in add
    listener = BaseHub.add(self, evtype, fileno, cb, tb, mac)
  File "/var/osl/temp/lib/python3.4/site-packages/eventlet/hubs/hub.py", line 177, in add
    evtype, fileno, evtype, cb, bucket[fileno]))
RuntimeError: Second simultaneous read on fileno 17 detected.  Unless you really know what you're doing, make sure that only one greenthread can read any particular socket.  Consider using a pools.Pool. If you do know what you're doing and want to disable this error, call eventlet.debug.hub_prevent_multiple_readers(False) - MY THREAD=<built-in method switch of greenlet.greenlet object at 0x7fd9440ff470>; THAT THREAD=FdListener('read', 17, <built-in method switch of greenlet.greenlet object at 0x7fd9440ff470>, <built-in method throw of greenlet.greenlet object at 0x7fd9440ff470>)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment