[Python] "Bad file descriptor" coming out of absolutely **nowhere** [closed]

Discussão em 'Python' iniciado por Stack, Janeiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    I'm not sure what's happening:

    Traceback (most recent call last):
    File "/app/endpoints/api_get_model_details.py", line 36, in api_get_model_details
    from .app import params, logger
    File "/app/endpoints/app.py", line 3394, in <module>
    app.run(host='0.0.0.0', port=8000, debug=True)
    File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 662, in run
    run_simple(t.cast(str, host), port, self, **options)
    File "/usr/local/lib/python3.10/site-packages/werkzeug/serving.py", line 1115, in run_simple
    run_with_reloader(
    File "/usr/local/lib/python3.10/site-packages/werkzeug/_reloader.py", line 452, in run_with_reloader
    signal.signal(signal.SIGTERM, lambda *args: sys.exit(0))
    File "/usr/local/lib/python3.10/signal.py", line 56, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
    ValueError: signal only works in main thread of the main interpreter
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
    File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1536, in __call__
    return self.wsgi_app(environ, start_response)
    File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1514, in wsgi_app
    response = self.handle_exception(e)
    File "/usr/local/lib/python3.10/site-packages/flask_cors/extension.py", line 194, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
    File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 1511, in wsgi_app
    response = self.full_dispatch_request()
    File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 919, in full_dispatch_request
    rv = self.handle_user_exception(e)
    File "/usr/local/lib/python3.10/site-packages/flask_cors/extension.py", line 194, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
    File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 917, in full_dispatch_request
    rv = self.dispatch_request()
    File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 902, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
    File "/app/endpoints/api_get_model_details.py", line 69, in api_get_model_details
    from .app import logger
    File "/app/endpoints/app.py", line 3394, in <module>
    app.run(host='0.0.0.0', port=8000, debug=True)
    File "/usr/local/lib/python3.10/site-packages/flask/app.py", line 662, in run
    run_simple(t.cast(str, host), port, self, **options)
    File "/usr/local/lib/python3.10/site-packages/werkzeug/serving.py", line 1093, in run_simple
    srv = make_server(
    File "/usr/local/lib/python3.10/site-packages/werkzeug/serving.py", line 930, in make_server
    return ThreadedWSGIServer(
    File "/usr/local/lib/python3.10/site-packages/werkzeug/serving.py", line 792, in __init__
    self.socket = socket.fromfd(fd, address_family, socket.SOCK_STREAM)
    File "/usr/local/lib/python3.10/socket.py", line 545, in fromfd
    nfd = dup(fd)
    OSError: [Errno 9] Bad file descriptor


    Looking at the last log I see OSError: [Errno 9] Bad file descriptor which is coming from socket.py (maybe a builtin?), looking up the trace I see werkzueg, further above I see flask and flask-cors, then werkzeug again, and at the very top:

    from .app import params, logger


    I can't seem to find anything wrong with this line. app.py does exist in the same directory. Even this isn't helpful:

    ValueError: signal only works in main thread of the main interpreter


    So if anyone knows what's happening please help TIA!

    Continue reading...

Compartilhe esta Página