mahmoud / clastic

🏔️ A functional web framework that streamlines explicit development practices while eliminating global state.
https://python-clastic.readthedocs.io/en/latest/
Other
158 stars 19 forks source link

Sending Responses Later #23

Closed danii closed 4 years ago

danii commented 4 years ago

Whenever a function is called to handle a request, it is required to return a response, and as such there is no way to send a response at a different point in time without use of some sleep method.

mahmoud commented 4 years ago

Hmm, the nature of HTTP is very request-response oriented. clastic is often used with other concurrency/parallelism frameworks (e.g., gevent), but what you say stays true: A request handler (endpoint function) must return a response.

danii commented 4 years ago

What about long polling systems? Where a request is made, and the response comes either before a typical browser's response timeout, or when new data is available?

mahmoud commented 4 years ago

Ah, well, long-polling fits into the HTTP request/response cycle via the mechanism you described (sleeping/checking/sleeping). Note that long-polling has become less popular these days as either short-polling often works fine, and WebSockets often work better for the remaining cases. (Note that clastic doesn't support WebSockets, yet.)

danii commented 4 years ago

Isn't sleeping / checking / sleeping blocking? If so does clastic support multi-threading?

mahmoud commented 4 years ago

Clastic definitely supports multithreading, though if you're expecting each worker process to field a lot of connections, you may want to use greenthreads or similar. I've written about our high-scale clastic usage here: https://medium.com/paypal-engineering/introducing-support-98945f023a8e

(Note that the port from WordPress to Medium messed with the formatting, but hopefully it's still comprehensible. :) )

danii commented 4 years ago

Alright, thank you!