etoropov
etoropov

Reputation: 1225

how to run a script with tqdm in background

Here is a simple script that uses the tqdm progress bar:

from tqdm import tqdm
from time import sleep

for i in tqdm(range(10000)):
  sleep(1)

Sometimes I want to let it run on my server and exit. Naturally, in those cases I'm not really interested in seeing the progress bar. I do this:

$ python mytest.py &
$ disown
$ exit

But once I exit, the process stops. Why does it happen and what to do about it?

Upvotes: 3

Views: 2234

Answers (1)

HelloGoodbye
HelloGoodbye

Reputation: 3922

I think the answer might be mentioned here.

Calling disown does not completely disconnect the process from the terminal. Since sys.stdin, sys.stout and sys.stderr are inherited from the shell, if the terminal is destroyed, the script will fail as soon as it tries to print to standard error, which tqdm attempts to do.

I don't know if you are running a subshell or if the exit command destroys the terminal. If the latter is true, that might explain why the process terminates. You could perhaps try to redirect all terminal output to /dev/null and see if that helps?

Upvotes: 1

Related Questions