This section of the documentation might be what you're looking for: https://twistedmatrix.com/documents/current/web/howto/web-in-60/asynchronous.html
If the tcp request to your upstream server is using some blocking (non-twisted) API, you could look into deferToThread. On Wed, 22 Apr 2020 at 17:17, Go Luhng <golu...@gmail.com> wrote: > I'd like to develop a server that maintains a TCP connection to an > upstream server, and listens for HTTP requests. Upon receiving an HTTP > request, the server will send a message upstream, wait for a response, > and return an HTTP response to the client which made the request. > > My background is in writing blocking web services, so my natural > instinct is to write a `get_result_for(query)` method that will take a > `query` string and return a result from the upstream TCP connection. > > I'm not sure whether writing such a method is possible in Twisted, > since it's basically a blocking method. I suspect I may have to use > Continuation-Passing Style instead, that is: provide a callback to > `get_result_for(query, callback)`. > > Even if that's the case, how do I return an HTTP response to the HTTP > client once the query result is available? > > _______________________________________________ > Twisted-Python mailing list > Twisted-Python@twistedmatrix.com > https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python >
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python