Find which python code are using more memory

Goodmorning, I’m working on a complex python project which is composed by different python codes and checking on the memory usage, I notice some jumps and I would like to trace which code among all codes generate that jumps. Maybe using also a background process wich analyse the list of pythons code are running and give me the memory usage. thank you very much
Best regards

From question it’s unclear what tools you are currently using so any suggestion might point towards something you already know. For example, there is built-in tracemalloc - Trace memory allocations. Among other things it provides:

Statistics on allocated memory blocks per filename and per line number: total size, number and average size of allocated memory blocks

thank you very much Aivar,

I’m using multiprocessing library. Maybe is difficult to describe entire project, but I would ask you another question. Often code stops when I try to copy many big files and read many files in different processes (launched in multiprocessing mode). I would ask if is possible to add a check of availability ram memory and retrying a process when memory is available. For example if copy file give me error, could be possible to repeat copy command until process successes, without stopping entire project?

thank you very much
Best regards