0

I am trying to run parallel processes where at the start of each process, it would print start, and then print done when that process finishes. For example

def process(i):

    print('starting process number %s' %i)
    ... do something ...
    print('finished process number %s' %i)
   
    return 

As you may expect, I can not just delete the previous line above whenever it finishes a process since this is a parallel job and multiple starting statments are printed before a single finished statment is done.

There is any way I can delete SPECIFIC strings of texts from the terminal so in the end I will be left with a terminal full of "finished" statments?

I am using Jupyter Interactive notebook on Vscode (which may or may not matter)

Thanks!

patrick7
  • 366
  • 1
  • 11
  • I don't know the exact answer, partly because you aren't detailing how this a parallel job: `joblib.Parallel`, multiprocessing, multithreading? However, I suspect this is well addressed if you add in the concepts you are looking for in your searches. For example, one of the was to mark progress is using tqdm to make progress bars or status messages and if you search you get things like: [here](https://stackoverflow.com/a/50925708/8508004), [here](https://stackoverflow.com/a/58936697/8508004), ... – Wayne Mar 03 '23 at 16:58
  • and [here](https://towardsdatascience.com/how-to-track-the-progress-of-parallel-tasks-in-python-with-tqdm-6d93339f03fe). There's other progress display methods, such as (Rich (https://rich.readthedocs.io/en/stable/progress.html) or [Halo](https://github.com/manrajgrover/halo) that you can tap into once you know the concepts. And if you want to keep it barebones, there is actually a backspace in Python that you can use in general to delete and replace text. I cannot tell if it would work here. Usually it works when you run scripts on the command line; however, the Jupyter ... – Wayne Mar 03 '23 at 17:04
  • interface often adds a little more complexity. I think this may get at it [here](https://github.com/jupyter/notebook/issues/5381#issue-601627673) but I'm not 100% sure what terminal you are working i?. If you are 100% just working in a normal terminal, just building in the backspacing from each job might help you. Maybe some fancier movement is what you need? See [here](https://stackoverflow.com/a/35519259/8508004). (A missed a tqdm example I forgot to include above is [here](https://stackoverflow.com/a/40133278/8508004).) – Wayne Mar 03 '23 at 17:12

0 Answers0