Giter VIP home page Giter VIP logo

Comments (1)

csernazs avatar csernazs commented on August 29, 2024 1

Hi,

That's correct, although the server is running in a different thread, it serves the request in a single-threaded mode (this allows us to write the code for ordered handlers easier, and makes the working simpler). That means that only one request handler can run at each time and while it is serving, no other handlers can be run.

Werkzeug and the underlying library supports threaded handling, but this is not availalbe in the pytest-httpserver's API. However with this modification you can experiment with it:

diff --git a/pytest_httpserver/httpserver.py b/pytest_httpserver/httpserver.py
index 332cd3d..a00ea6d 100644
--- a/pytest_httpserver/httpserver.py
+++ b/pytest_httpserver/httpserver.py
@@ -872,7 +872,7 @@ class HTTPServer:   # pylint: disable=too-many-instance-attributes
         if self.is_running():
             raise HTTPServerError("Server is already running")
 
-        self.server = make_server(self.host, self.port, self.application, ssl_context=self.ssl_context)
+        self.server = make_server(self.host, self.port, self.application, ssl_context=self.ssl_context, threaded=True)
         self.port = self.server.port  # Update port (needed if `port` was set to 0)
         self.server_thread = threading.Thread(target=self.thread_target)
         self.server_thread.start()

I have not tried this but this idea comes from https://github.com/pallets/werkzeug/blob/main/src/werkzeug/serving.py#L746.

If it works for you, you can subclass from HTTPServer and override this method.

Asyncio support is not planned to pytest-httpserver, it would need a radical re-write I'm afraid.

from pytest-httpserver.

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.