Python Forum
How to Host a REST API that executes a PYTHON script on the WEB SERVER
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Host a REST API that executes a PYTHON script on the WEB SERVER
#5
Due the limitation of the GIL, threading is not good for CPU intensive tasks.
They should run in a different process (Multiprocessing).

There are some Modules, which are similar to Flask, but async.
Usually one Thread which handles the requests, is enough.
Most of the time, the WebServer is waiting for IO (sockets, Databases, etc.).

The question is, do you need to handle so many requests per second?
If you have blocking CPU intensive tasks, you should avoid executing them in your WebServer code.
In this case this tasks should be done by other Processes. There are different ways and libraries to handle it.
Multiprocessing together with message queues can handle your CPU intensive tasks.

The benefit is, that async code looks like synchronous code. But you have always to remind, never call blocking functions.
Calling blocking functions in async code, blocks your whole WebServer. Even time.sleep(x) have to be replaced by await asyncio.sleep(x)

I could not remind the name of the other framework. It is also similar, but they are going a different way.

Then you can use also other Frameworks:

Django has also support for asyncio. They made a new standard called ASGI.

There are still mature frameworks like Tornado and Twisted which also supports async programming.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: How to Host a REST API that executes a PYTHON script on the WEB SERVER - by DeaD_EyE - Jan-25-2019, 02:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Script does not work on Linux server scrapemasta 0 272 Mar-22-2024, 11:07 AM
Last Post: scrapemasta
  Choosing Python web host? Crododo 2 2,370 Jan-19-2023, 02:05 PM
Last Post: prvncpa
  deploying python script on a server rickyrt 0 1,479 Aug-31-2021, 04:03 PM
Last Post: rickyrt
  Python Rest API Public/Secret Keys Authentication Nonce dn237 1 2,921 Oct-31-2019, 02:07 AM
Last Post: dn237
  Python Flask REST API vndywarhol 1 2,998 Sep-28-2018, 12:43 PM
Last Post: thomasp
  Begginer - How to choose a server to run my Python script with MongoDB? Mapl 1 3,762 Oct-24-2017, 01:02 PM
Last Post: DeaD_EyE
  Please give me some advice on how to host python apps on a vps FonCheato 1 3,344 Feb-02-2017, 02:21 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020