Skip to content

importing manhole crashes with AttributeError in weird circumstances #70

@anarcat

Description

@anarcat

So this one is weird, bear with me.

See, eventlet is broken, and kind of dead. If you visit their documentation now, it says:

New usages of eventlet are now heavily discouraged!

Here, in particular, import manhole completely crashes with a full backtrace, i think partly because of eventlet:

anarcat@angela:~/s/asncounter> python -c 'import manhole'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import manhole
  File "/usr/lib/python3/dist-packages/manhole/__init__.py", line 44, in <module>
    from eventlet.patcher import original as _original
  File "/usr/lib/python3/dist-packages/eventlet/__init__.py", line 6, in <module>
    from eventlet import convenience
  File "/usr/lib/python3/dist-packages/eventlet/convenience.py", line 7, in <module>
    from eventlet.green import socket
  File "/usr/lib/python3/dist-packages/eventlet/green/socket.py", line 21, in <module>
    from eventlet.support import greendns
  File "/usr/lib/python3/dist-packages/eventlet/support/greendns.py", line 78, in <module>
    setattr(dns, pkg, import_patched('dns.' + pkg))
                      ~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/eventlet/support/greendns.py", line 60, in import_patched
    return patcher.import_patched(module_name, **modules)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/eventlet/patcher.py", line 136, in import_patched
    return inject(
        module_name, None, *additional_modules + tuple(kw_additional_modules.items())
    )
  File "/usr/lib/python3/dist-packages/eventlet/patcher.py", line 113, in inject
    module = __import__(module_name, {}, {}, module_name.split(".")[:-1])
  File "/usr/lib/python3/dist-packages/dns/asyncquery.py", line 40, in <module>
    from dns.query import (
    ...<12 lines>...
    )
  File "/usr/lib/python3/dist-packages/dns/query.py", line 66, in <module>
    import httpcore._backends.sync
  File "/usr/lib/python3/dist-packages/httpcore/__init__.py", line 1, in <module>
    from ._api import request, stream
  File "/usr/lib/python3/dist-packages/httpcore/_api.py", line 7, in <module>
    from ._sync.connection_pool import ConnectionPool
  File "/usr/lib/python3/dist-packages/httpcore/_sync/__init__.py", line 1, in <module>
    from .connection import HTTPConnection
  File "/usr/lib/python3/dist-packages/httpcore/_sync/connection.py", line 14, in <module>
    from .._synchronization import Lock
  File "/usr/lib/python3/dist-packages/httpcore/_synchronization.py", line 12, in <module>
    import trio
  File "/usr/lib/python3/dist-packages/trio/__init__.py", line 25, in <module>
    from . import abc, from_thread, lowlevel, socket, to_thread
  File "/usr/lib/python3/dist-packages/trio/socket.py", line 16, in <module>
    from . import _socket
  File "/usr/lib/python3/dist-packages/trio/_socket.py", line 542, in <module>
    class SocketType:
    ...<221 lines>...
                raise NotImplementedError
  File "/usr/lib/python3/dist-packages/trio/_socket.py", line 755, in SocketType
    @_wraps(_stdlib_socket.socket.sendmsg, assigned=(), updated=())
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'GreenSocket' has no attribute 'sendmsg'
anarcat@angela:~/s/asncounter[1]> 

Weird, no?

What's even weirder is I can't reproduce this in a virtual environment. Just installing manhole in there is not enough. I've also tried installing trio, eventlet, and all bunch of things, I can't trigger this:

python3 -m venv ~/.venvs/manhole
~/.venvs/manhole/bin/pip install manhole trio eventlet httpcore trio-websocket
~/.venvs/manhole/bin/python -c import manhole

... just succeeds. So there's something in my import path that makes manhole just freak out and crash like this. Try as I might, I couldn't quite figure it out. I even strace'd everything python -c 'import manhole' to try to reproduce.

So I've given up. Instead, i've patched manhole to ignore errors from eventlet and carry on. I'll send a PR.

See also python-trio/trio#3015

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions