Skip to content

fastwsgi blocks OTHER threads from executing #51

Open
@ibrewster

Description

@ibrewster

Calling fastwsgi.run should block the main thread, but release the GIL, allowing other threads to run (I/O wait). However, the observed behavior is that all threads are blocked, implying the GIL is not released while fastwsgi is waiting (though the actual issue may be different).

Observe the difference in behavior with this toy code when using fastwsgi.run vs. the development flask app.run

import threading, time
import fastwsgi

from flask import Flask

app = Flask(__name__)

@app.get('/')
def hello_world():
    return 'Hello, World!', 200


def dummy_thread():
    while True:
        print("Staying alive!")
        time.sleep(1)
 
if __name__ == '__main__':
    thread = threading.Thread(target=dummy_thread)
    thread.start()
    time.sleep(3) # Should print "Staying alive!" a number of times
    
    # This should block the main thread, but the "staying alive" thread should keep running
    # Using fastwsgi, all stops.
    fastwsgi.run(wsgi_app=app, host='0.0.0.0', port=5000)
    
    # Using the flask provided development server, the other thread continues as expected.
    # app.run(host='0.0.0.0', port=5000)

In many (most?) apps this would not be an issue, however it makes fastwsgi unusable in any application that requires some sort of background processing, such as my RaspberryPi app that provides a web server, but also listens for button presses.

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