flask-testing icon indicating copy to clipboard operation
flask-testing copied to clipboard

switch to using a thread for the live server

Open danchr opened this issue 8 years ago • 3 comments

Running the server in a thread works quite well, and prevents any issues with communication between processes. Furthermore, it fixes stdio capturing to work as expected.

Tested by using something similar in my own test suite on Python 3.6, and by running Flask-Testing's own suite on Python 2.6, 2.7 and 3.6.

danchr avatar Aug 03 '17 10:08 danchr

Excellent idea! Thanks for the contribution.

I am not familiar with Werkzeug's API to create servers but it looks like there is an option for threading here: https://github.com/pallets/werkzeug/blob/master/werkzeug/serving.py#L576. Is there a reason you're using a thread over the threaded mixin server?

jcomo avatar Aug 03 '17 22:08 jcomo

Is there a reason you're using a thread over the threaded mixin server?

Well, yes; I wanted to use the serve_forever() method, with blocks the thread. I don't think the threaded server helps with that, but rather allows the server to process multiple requests concurrently.

I tried switching my application to the Flask configuration system, and noticed that it didn't seem to affect the live server with these changes. I'll try to come up with a test to check whether that's a regression.

danchr avatar Aug 11 '17 06:08 danchr

That was my thought - wanted to make sure I had the right idea. This is great. Let's get a test for that regression if you can manage it and then we'll merge

jcomo avatar Aug 14 '17 17:08 jcomo