It is not generally possible to measure resource requirements in advance, so you’ll have to test under a representative workload.
While the task manager can provide highly accurate results for a point in time, you’re likely more interested in total CPU usage and maximum memory usage. On the Linux command line, you can easily gather these statistics with the
Note that any such measurements will be inaccurate if your Python code launches additional processes. This is somewhat common in Python programs with high CPU usage, since forking additional processes is the only way to gain parallelism in CPython, i.e. to use more than one CPU.
In some cases, calculating memory requirements is possible though. If your program processes a single large data structure, the size of this structure will likely dominate memory usage. For example, an image processing script will likely spend most of its memory on the image buffer.
Python also has some builtin functions for monitoring resource usage. The
os.times() function can return the used CPU time, including CPU used by subprocesses. The
resource.getrusage() function can return information about memory usage, but is very low-level.