Search code examples
pythonbashpython-2.7tmux

Does ending a python 2.7 print statement with a comma not work in tmux?


Pretty much just what's in the question. I have a slow process running in tmux and wanted to document progress through the for loop by printing the loop variable.

print 'Progress...', 
for i in range(15):
    ...
    print i, 
print

This works in my terminal. In tmux, however, it doesn't print anything until it hits a new-line command with the last print. Does printing on the same line repeatedly not work in tmux? How could I remedy this? It's not a big deal, I'm just curious what I can do as I don't know much about bash scripting.

Thanks!


Solution

  • This is almost surely due to output buffering. You can check that's the cause by calling flush:

    import sys
    print 'Progress...', 
    for i in range(15):
        ...
        print i, 
        sys.stdout.flush()
    print
    

    If this fixes your problem, you might consider to run python unbuffered.