Giter Site home page Giter Site logo

Comments (4)

A5rocks avatar A5rocks commented on August 21, 2024

As a quick fix you can probably import trio before monkey patching. This will cache trio with un-patched system things.

There has to be a way to fix this that isn't just a game of whack-a-mole but I don't have any ideas.

from trio.

maldororxul avatar maldororxul commented on August 21, 2024

If I import trio before monkey patching it will fall with "AttributeError: module 'select' has no attribute 'epoll'".

I ended up with this to avoid both attribute errors:

def monkey_patch_trio():
    try:
        import select
        if not hasattr(select, 'epoll'):
            class FakeEpoll:
                def __init__(self, *args, **kwargs):
                    raise NotImplementedError("epoll is not supported on this platform")

            fake_select_module = ModuleType("select")
            fake_select_module.epoll = FakeEpoll
            sys.modules["select"] = fake_select_module

        # Patch GreenSocket before trio._socket is imported
        from eventlet.greenio.base import GreenSocket as EventletGreenSocket

        if not hasattr(EventletGreenSocket, 'sendmsg'):
            setattr(EventletGreenSocket, 'sendmsg', lambda *args, **kwargs: None)
        if not hasattr(EventletGreenSocket, 'recvmsg'):
            setattr(EventletGreenSocket, 'recvmsg', lambda *args, **kwargs: None)
        if not hasattr(EventletGreenSocket, 'recvmsg_into'):
            setattr(EventletGreenSocket, 'recvmsg_into', lambda *args, **kwargs: None)

        # Now import trio._socket
        import trio._socket as trio_socket
        import socket as _stdlib_socket
        from functools import wraps as _wraps

        class PatchedSocketType(trio_socket.SocketType):
            @_wraps(_stdlib_socket.socket.sendmsg, assigned=(), updated=())
            def sendmsg(self, *args, **kwargs):
                raise NotImplementedError("sendmsg is not supported on this platform")

            @_wraps(_stdlib_socket.socket.recvmsg, assigned=(), updated=())
            def recvmsg(self, *args, **kwargs):
                raise NotImplementedError("recvmsg is not supported on this platform")

            @_wraps(_stdlib_socket.socket.recvmsg_into, assigned=(), updated=())
            def recvmsg_into(self, *args, **kwargs):
                raise NotImplementedError("recvmsg_into is not supported on this platform")

        trio_socket.SocketType = PatchedSocketType

    except ImportError:
        pass

from trio.

A5rocks avatar A5rocks commented on August 21, 2024

Sorry, I mean import trio before running eventlet.monkey_patch().

from trio.

A5rocks avatar A5rocks commented on August 21, 2024

Ok I thought about this some more and this is totally just an eventlet bug. They claim GreenSocket is "100% api compatible with socket.socket":

https://github.com/eventlet/eventlet/blob/8bac9b2bb5ba02d42305446327a117ff51af177b/eventlet/greenio/base.py#L119-L122

from trio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.