Sys.stdout in python cause cmd to hang when used more than 1000 times

396 views Asked by At

I want to use sys.stdout to show progress. There is no percentage since I don't and can't know the max value, so I can't use progress bar library.

The problem is, I need to call sys.stdout.write() more than 1000 times, and it makes the command line irresponsive. It won't even respond to KeyboardInterrupt. The problem does not happen with print though, but I kind of want to use sys.stdout since it might help for logging.

Here is my code:

while len(self.tocrawl) != 0:
            self.__crawling()
            sys.stdout.write('Crawled {} URLs!\r'.format(self.nb_url))
            sys.stdout.flush()
0

There are 0 answers