python-trio / trio

Trio – a friendly Python library for async concurrency and I/O
https://trio.readthedocs.io
Other
6.23k stars 343 forks source link

Gunicorn worker fails to boot due to NotImplementedError #2960

Open codebanesr opened 9 months ago

codebanesr commented 9 months ago

Description: I'm encountering a NotImplementedError: unsupported platform which causes my Gunicorn worker process to fail. This seems to be originating from the httpx/trio libraries. Has anyone else experienced similar issues?

Error Traceback:

[2024-02-18 21:08:17 -0800] [42822] [ERROR] Exception in worker process
Traceback (most recent call last):
 File "/opt/homebrew/lib/python3.11/site-packages/gunicorn/arbiter.py", line 609, in spawn_worker
  worker.init_process()
 File "/opt/homebrew/lib/python3.11/site-packages/gunicorn/workers/ggevent.py", line 147, in init_process
  super().init_process()
 File "/opt/homebrew/lib/python3.11/site-packages/gunicorn/workers/base.py", line 134, in init_process
  self.load_wsgi()
 File "/opt/homebrew/lib/python3.11/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
  self.wsgi = self.app.wsgi()
        ^^^^^^^^^^^^^^^
  ... (Remainder of traceback) 
NotImplementedError: unsupported platform

Environment:

Let me know if any more details are necessary.

codebanesr commented 9 months ago

The error originates here, and it only happens when i try to run the app with gunicorn and eventlet

Screenshot 2024-02-18 at 9 19 15 PM
CoolCat467 commented 9 months ago

This sounds incredibly similar to #2848.

EDIT: In #2848, we found out that basically gevent monkey-patches some things in the select module and that breaks things for trio. Apparently this is intended according to https://github.com/gevent/gevent/issues/2008.

According to gunicorn docs (https://docs.gunicorn.org/en/stable/settings.html#worker-class), apparently you might want to create a subclass for gunicorn.workers.base.Worker that uses trio

EDIT II: It might be worth looking into https://github.com/pgjones/hypercorn, which is also a wsgi server. I've personally had a lot of success working with it (my project sane scanner server uses it), and it has built-in support for a trio worker class.

jakkdl commented 9 months ago

The error originates here, and it only happens when i try to run the app with gunicorn and eventlet Screenshot 2024-02-18 at 9 19 15 PM

right yeah, if we're getting here in the logic then we're neither on windows nor linux (true), and the select module does not appear to have kqueue (so apparently gevent.select does not have kqueue either. So indeed similar to #2848, but would not be resolved by #2928.

A5rocks commented 9 months ago

Yeah in #2928 I could make things work via gevent.monkey.get_original but I don't think that's really the right behavior. That will make trio.run block, I think.

Not entirely sure what is the best outcome to have here.

A5rocks commented 3 months ago

@codebanesr does this still fail? That PR was merged a while ago but I forgot to check back here.

abhra-bv commented 1 month ago

I am using mysql-connector in a flask env . I have gevent for sockets, and the trio still errors out on mac. Im just using mac for development purposes.any way we can get past this in a mac

A5rocks commented 1 month ago

I am using mysql-connector in a flask env . I have gevent for sockets, and the trio still errors out on mac. Im just using mac for development purposes.any way we can get past this in a mac

Sorry I forgot about one extra workaround I should have specified in your issue: httpx, or well really httpcore as of 1.0.6 handles trio raising this error as if trio doesn't exist. So you might be able to bump your dependencies and that will fix things.