Partial profiling
In many scenarios, profilers will be useful in environments where the system is in operation and we cannot wait until the process finishes before obtaining profiling information. Typical scenarios are web requests.
If we want to analyze a particular web request, we may need to start a web server, produce a single request, and stop the process to obtain the result. This doesn't work as well as you may think due to some problems that we will see.
But first, let's create some code to explain this situation.
Example web server returning prime numbers
We will use the final version of the function check_if_prime
and create a web service that returns all the primes up to the number specified in the path of the request. The code will be the following, and it's fully available in the server.py
file on GitHub at https://github.com/PacktPublishing/Python-Architecture-Patterns/blob/main/chapter_14_profiling/server.py.
from http.server import...