0

I have a Python code with a loop that I run on my bash terminal. For some reason when I take a look at the task manager the CPU appears unstable:

The code is stuck for tens of seconds and then goes on. I work on Xubuntu and have 8 cores on my computer and using multiprocessing in my Python code doesn't not solve the problem. So I suspect the problem comes from the OS rather than from my code, just a guess. Any idea?

closed as off-topic by vidarlo, karel, Kulfy, user535733, waltinator May 17 at 14:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – karel, Kulfy
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    This is impossible to answer unless we know what your code is doing. If it's spending ten seconds reading from disk, CPU will be idle, and no matter of multithreading will speed it up...Furthermore, just import multiprocessing will not make your application multithreaded. You have to actually spawn threads. Multiprocessing is a framework for managing those threads. Furthermore, you should attach a debugger and check where your code waits for those seconds. – vidarlo May 14 at 18:30
  • I'm processing some waveforms in a loop. In each iteration I read the waveform, create an output filename based on the origin time of the waveform, check if the filename already exists in the output directory (using os.path.exists, if it exists then I don't process the waveform), process the waveform, and finally pickle.dump the file in the output directory. I'm logging some elements into a logging file using the logging module. I'm wondering if os.path.exists is the cause of problem... – runtheBC May 14 at 18:58
  • Attach a debugger and see where it stops. – vidarlo May 14 at 18:59
  • Thanks for your time @vidarlo but I'm not sure what do you mean by attach a debugger, you mean running the profiler in Spyder? – runtheBC May 14 at 19:14
  • 1
    Yes you're right but I thought it may be link to CPU usage on ubuntu. Anyway thanks for your help, I'll try to dig deeper in the my code. – runtheBC May 14 at 19:35
0

After some investigation it seems that the issue came from the code where I made a call to a function to download data from an external server. As my internet connection was unstable I decided to call that function in a try-catch block, going out a the loop only when connection was found. For some reason this implementation didn't work very well. So the problem came for my connection.

Not the answer you're looking for? Browse other questions tagged or ask your own question.