如何刷新Python输出的输出?

时间:2021-02-27 21:45:46

How do I force Python's print function to output to the screen?

如何强制Python的打印函数输出到屏幕?

This is not a duplicate of Disable output buffering - the linked question is attempting unbuffered output, while this is more general. The top answers in that question are too powerful or involved for this one (they're not good answers for this), and this question can be found on Google by a relative newbie.

这不是禁用输出缓冲的复制——链接的问题是尝试没有缓冲的输出,而这是更一般的。在这个问题上,最重要的答案是太过强大或者涉及到这个问题(他们不是很好的答案),这个问题可以通过一个相对的新手在谷歌上找到。

14 个解决方案

#1


1002  

import sys
sys.stdout.flush()

Print by default prints to sys.stdout.

默认打印到sys.stdout。

References:

引用:

#2


275  

Running python -h, I see a command line option:

运行python -h,我看到命令行选项:

-u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x see man page for details on internal buffering relating to '-u'

-u:无缓冲二进制stdout和stderr;另外,PYTHONUNBUFFERED=x看到了关于“-u”内部缓冲的详细信息

Here is the relevant doc.

这是相关的医生。

#3


222  

Since Python 3.3, you can force the normal print() function to flush without the need to use sys.stdout.flush(); just set the "flush" keyword argument to true. From the documentation:

由于Python 3.3,您可以强制正常的print()函数在不需要使用sys.stdout.flush()的情况下刷新。只需将“flush”关键字参数设置为true。从文档:

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

打印(*对象,sep=', end='\n', file=sys。stdout,冲洗= False)

Print objects to the stream file, separated by sep and followed by end. sep, end and file, if present, must be given as keyword arguments.

将对象打印到流文件中,由sep分隔,然后结束。sep、end和file(如果存在的话)必须作为关键字参数。

All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no objects are given, print() will just write end.

所有非关键字参数都转换为字符串,如str(),并写入到流中,由sep分隔,然后结束。sep和end都必须是字符串;它们也可以是None,这意味着使用默认值。如果没有给定对象,print()将写入end。

The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used. Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.

文件参数必须是具有写(string)方法的对象;如果它不存在或没有,sys。将使用标准输出。输出是否被缓冲通常是由文件决定的,但是如果刷新关键字参数是正确的,则流被强制刷新。

#4


78  

How to flush output of Python print?

I suggest five ways of doing this:

我建议五种方法:

  • Call print with the flush=True argument.
  • 用flush=True参数调用print。
  • Call file.flush() on the output file (we can wrap python 2's print function to do this), for example, sys.stdout
  • 在输出文件上调用file.flush(),例如,sys.stdout,我们可以将python 2的打印函数封装到这个文件中。
  • apply this to every print function call in the module with a partial function,
    print = partial(print, flush=True) applied to the module global.
  • 将此应用于模块中的每个打印函数调用,并使用部分函数,print = partial(print, flush=True)应用于模块全局。
  • apply this to the process with a flag (-u) passed to the interpreter command
  • 将此应用程序应用于传递给解释器命令的标记(-u)。
  • apply this to every python process in your environment with PYTHONUNBUFFERED=TRUE (and unset the variable to undo this).
  • 在您的环境中使用PYTHONUNBUFFERED=TRUE将此应用到每个python进程中(并取消设置该变量以撤消此操作)。

Python 3.3+

Using Python 3.3 or higher, you can just provide flush=True as a keyword argument to the print function:

使用Python 3.3或更高版本,您可以只提供flush=True作为打印函数的关键字参数:

print('foo', flush=True) 

Python 2 (or < 3.3)

They did not backport the flush argument to Python 2.7 So if you're using Python 2 (or less than 3.3), and want code that's compatible with both 2 and 3, may I suggest the following compatibility code. (Note the __future__ import must be at/very "near the top of your module"):

如果您使用的是Python 2(或小于3.3),并且希望代码与2和3兼容,那么我建议您使用以下兼容性代码。(注:__future__ import必须位于/非常“靠近模块顶部”):

from __future__ import print_function
import sys

if sys.version_info[:2] < (3, 3):
    old_print = print
    def print(*args, **kwargs):
        flush = kwargs.pop('flush', False)
        old_print(*args, **kwargs)
        if flush:
            file = kwargs.get('file', sys.stdout)
            # Why might file=None? IDK, but it works for print(i, file=None)
            file.flush() if file is not None else sys.stdout.flush()

The above compatibility code will cover most uses, but for a much more thorough treatment, see the six module.

上面的兼容性代码将涵盖大多数用途,但要进行更彻底的处理,请参见这6个模块。

Alternatively, you can just call file.flush() after printing, for example, with the print statement in Python 2:

或者,您也可以调用file.flush()在打印后,例如,使用Python 2中的print语句:

import sys
print 'delayed output'
sys.stdout.flush()

Changing the default in one module to flush=True

You can change the default for the print function by using functools.partial on the global scope of a module:

您可以使用功能工具来更改打印功能的默认值。部分关于模块的全局范围:

import functools
print = functools.partial(print, flush=True)

if you look at our new partial function, at least in Python 3:

如果你看一下我们的新部分函数,至少在Python 3中:

>>> print = functools.partial(print, flush=True)
>>> print
functools.partial(<built-in function print>, flush=True)

We can see it works just like normal:

我们可以看到它正常运行:

>>> print('foo')
foo

And we can actually override the new default:

我们可以重写新的默认值:

>>> print('foo', flush=False)
foo

Note again, this only changes the current global scope, because the print name on the current global scope will overshadow the builtin print function (or dereference the compatibility function, if using Python 2, in that current global scope).

请再次注意,这只会改变当前全局范围,因为当前全局范围内的打印名称将会覆盖builtin打印函数(如果在当前全局范围内使用Python 2,则取消兼容函数)。

If you want to do this inside a function instead of on a module's global scope, you should give it a different name, e.g.:

如果您想在函数内而不是在模块的全局范围内执行这个操作,您应该给它一个不同的名称,例如:

def foo():
    printf = functools.partial(print, flush=True)
    printf('print stuff like this')

If you declare it a global in a function, you're changing it on the module's global namespace, so you should just put it in the global namespace, unless that specific behavior is exactly what you want.

如果您在函数中声明它是全局的,那么您将在模块的全局命名空间中更改它,因此您应该将它放在全局命名空间中,除非您想要的正是特定的行为。

Changing the default for the process

I think the best option here is to use the -u flag to get unbuffered output.

我认为这里最好的选择是使用-u标志来获得无缓冲输出。

$ python -u script.py

or

$ python -um package.module

From the docs:

从文档:

Force stdin, stdout and stderr to be totally unbuffered. On systems where it matters, also put stdin, stdout and stderr in binary mode.

Force stdin, stdout和stderr完全没有缓冲。在它重要的系统上,也将stdin、stdout和stderr置于二进制模式。

Note that there is internal buffering in file.readlines() and File Objects (for line in sys.stdin) which is not influenced by this option. To work around this, you will want to use file.readline() inside a while 1: loop.

注意,在file.readlines()和File对象(在sys.stdin中为行)中有内部缓冲,而这并不受此选项的影响。为了解决这个问题,您需要在一个while循环中使用file.readline()。

Changing the default for the shell operating environment

You can get this behavior for all python processes in the environment or environments that inherit from the environment if you set the environment variable to a nonempty string:

如果将环境变量设置为非空字符串,则可以在环境或环境中从环境继承所有python进程的行为。

e.g., in Linux or OSX:

在Linux或OSX中:

$ export PYTHONUNBUFFERED=TRUE

or Windows:

或窗口:

C:\SET PYTHONUNBUFFERED=TRUE

from the docs:

从文档:

PYTHONUNBUFFERED

PYTHONUNBUFFERED

If this is set to a non-empty string it is equivalent to specifying the -u option.

如果将此设置为非空字符串,则等效于指定-u选项。


Addendum

Here's the help on the print function from Python 2.7.12 - note that there is no flush argument:

这里是Python 2.7.12的打印函数的帮助——注意没有泛红的参数:

>>> from __future__ import print_function
>>> help(print)
print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout)

    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file: a file-like object (stream); defaults to the current sys.stdout.
    sep:  string inserted between values, default a space.
    end:  string appended after the last value, default a newline.

#5


64  

Also as suggested in this blog one can reopen sys.stdout in unbuffered mode:

正如在本博客中所建议的,我们可以重新打开sys。stdout中无缓冲的模式:

sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

Each stdout.write and print operation will be automatically flushed afterwards.

每个stdout。写入和打印操作之后将自动刷新。

#6


28  

Using the -u command-line switch works, but it is a little bit clumsy. It would mean that the program would potentially behave incorrectly if the user invoked the script without the -u option. I usually use a custom stdout, like this:

使用-u命令行开关工作,但是有点笨拙。这意味着如果用户在没有-u选项的情况下调用脚本,程序可能会出现错误。我通常使用定制的stdout,像这样:

class flushfile(object):
  def __init__(self, f):
    self.f = f

  def write(self, x):
    self.f.write(x)
    self.f.flush()

import sys
sys.stdout = flushfile(sys.stdout)

... Now all your print calls (which use sys.stdout implicitly), will be automatically flushed.

…现在所有打印调用(使用sys)。stdout隐式),将自动刷新。

#7


19  

With Python 3.x they extended the print() function:

Python 3。他们扩展了print()函数:

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

打印(*对象,sep=', end='\n', file=sys。stdout,冲洗= False)

So, you can just do:

所以,你可以这样做:

print("Visiting toilet", flush=True)

打印(“去厕所”,冲洗= True)


Python Docs Entry

Python文档条目

#8


17  

Why not try using an unbuffered file?

为什么不尝试使用一个无缓冲文件呢?

f = open('xyz.log', 'a', 0)

OR

sys.stdout = open('out.log', 'a', 0)

#9


12  

import sys
print 'This will be output immediately.'
sys.stdout.flush()

#10


11  

Dan's idea doesn't quite work:

丹的想法并不奏效:

#!/usr/bin/env python
class flushfile(file):
    def __init__(self, f):
        self.f = f
    def write(self, x):
        self.f.write(x)
        self.f.flush()

import sys
sys.stdout = flushfile(sys.stdout)

print "foo"

The result:

结果:

Traceback (most recent call last):
  File "./passpersist.py", line 12, in <module>
    print "foo"
ValueError: I/O operation on closed file

I believe the problem is that it inherits from the file class, which actually isn't necessary. According to the docs for sys.stdout:

我认为问题在于它继承了文件类,而这实际上是不必要的。根据sys.stdout的文档:

stdout and stderr needn’t be built-in file objects: any object is acceptable as long as it has a write() method that takes a string argument.

stdout和stderr不必是内置的文件对象:只要它有一个写()方法来接受字符串参数,任何对象都是可以接受的。

so changing

所以改变

class flushfile(file):

to

class flushfile(object):

makes it work just fine.

让它工作得很好。

#11


6  

Here is my version, which provides writelines() and fileno(), too:

以下是我的版本,提供了writelines()和fileno():

class FlushFile(object):
    def __init__(self, fd):
        self.fd = fd

    def write(self, x):
        ret = self.fd.write(x)
        self.fd.flush()
        return ret

    def writelines(self, lines):
        ret = self.writelines(lines)
        self.fd.flush()
        return ret

    def flush(self):
        return self.fd.flush

    def close(self):
        return self.fd.close()

    def fileno(self):
        return self.fd.fileno()

#12


5  

Loved Dan's solution! For python3 do:

爱丹的解决方案!python3做:

import io,sys
class flushfile:
    def __init__(self, f):
        self.f = f
    def write(self, x):
        self.f.write(x)
        self.f.flush()
sys.stdout = flushfile(sys.stdout)

#13


2  

In Python 3 you can overwrite print function with default set to flush = True

在Python 3中,您可以使用默认设置来覆盖print函数。

def print(*objects, sep=' ', end='\n', file=sys.stdout, flush=True):
    __builtins__.print(*objects, sep=sep, end=end, file=file, flush=flush)

#14


2  

I did it like this in Python 3.4:

我在python3.4中这样做了

'''To write to screen in real-time'''
message = lambda x: print(x, flush=True, end="")
message('I am flushing out now...')

#1


1002  

import sys
sys.stdout.flush()

Print by default prints to sys.stdout.

默认打印到sys.stdout。

References:

引用:

#2


275  

Running python -h, I see a command line option:

运行python -h,我看到命令行选项:

-u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x see man page for details on internal buffering relating to '-u'

-u:无缓冲二进制stdout和stderr;另外,PYTHONUNBUFFERED=x看到了关于“-u”内部缓冲的详细信息

Here is the relevant doc.

这是相关的医生。

#3


222  

Since Python 3.3, you can force the normal print() function to flush without the need to use sys.stdout.flush(); just set the "flush" keyword argument to true. From the documentation:

由于Python 3.3,您可以强制正常的print()函数在不需要使用sys.stdout.flush()的情况下刷新。只需将“flush”关键字参数设置为true。从文档:

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

打印(*对象,sep=', end='\n', file=sys。stdout,冲洗= False)

Print objects to the stream file, separated by sep and followed by end. sep, end and file, if present, must be given as keyword arguments.

将对象打印到流文件中,由sep分隔,然后结束。sep、end和file(如果存在的话)必须作为关键字参数。

All non-keyword arguments are converted to strings like str() does and written to the stream, separated by sep and followed by end. Both sep and end must be strings; they can also be None, which means to use the default values. If no objects are given, print() will just write end.

所有非关键字参数都转换为字符串,如str(),并写入到流中,由sep分隔,然后结束。sep和end都必须是字符串;它们也可以是None,这意味着使用默认值。如果没有给定对象,print()将写入end。

The file argument must be an object with a write(string) method; if it is not present or None, sys.stdout will be used. Whether output is buffered is usually determined by file, but if the flush keyword argument is true, the stream is forcibly flushed.

文件参数必须是具有写(string)方法的对象;如果它不存在或没有,sys。将使用标准输出。输出是否被缓冲通常是由文件决定的,但是如果刷新关键字参数是正确的,则流被强制刷新。

#4


78  

How to flush output of Python print?

I suggest five ways of doing this:

我建议五种方法:

  • Call print with the flush=True argument.
  • 用flush=True参数调用print。
  • Call file.flush() on the output file (we can wrap python 2's print function to do this), for example, sys.stdout
  • 在输出文件上调用file.flush(),例如,sys.stdout,我们可以将python 2的打印函数封装到这个文件中。
  • apply this to every print function call in the module with a partial function,
    print = partial(print, flush=True) applied to the module global.
  • 将此应用于模块中的每个打印函数调用,并使用部分函数,print = partial(print, flush=True)应用于模块全局。
  • apply this to the process with a flag (-u) passed to the interpreter command
  • 将此应用程序应用于传递给解释器命令的标记(-u)。
  • apply this to every python process in your environment with PYTHONUNBUFFERED=TRUE (and unset the variable to undo this).
  • 在您的环境中使用PYTHONUNBUFFERED=TRUE将此应用到每个python进程中(并取消设置该变量以撤消此操作)。

Python 3.3+

Using Python 3.3 or higher, you can just provide flush=True as a keyword argument to the print function:

使用Python 3.3或更高版本,您可以只提供flush=True作为打印函数的关键字参数:

print('foo', flush=True) 

Python 2 (or < 3.3)

They did not backport the flush argument to Python 2.7 So if you're using Python 2 (or less than 3.3), and want code that's compatible with both 2 and 3, may I suggest the following compatibility code. (Note the __future__ import must be at/very "near the top of your module"):

如果您使用的是Python 2(或小于3.3),并且希望代码与2和3兼容,那么我建议您使用以下兼容性代码。(注:__future__ import必须位于/非常“靠近模块顶部”):

from __future__ import print_function
import sys

if sys.version_info[:2] < (3, 3):
    old_print = print
    def print(*args, **kwargs):
        flush = kwargs.pop('flush', False)
        old_print(*args, **kwargs)
        if flush:
            file = kwargs.get('file', sys.stdout)
            # Why might file=None? IDK, but it works for print(i, file=None)
            file.flush() if file is not None else sys.stdout.flush()

The above compatibility code will cover most uses, but for a much more thorough treatment, see the six module.

上面的兼容性代码将涵盖大多数用途,但要进行更彻底的处理,请参见这6个模块。

Alternatively, you can just call file.flush() after printing, for example, with the print statement in Python 2:

或者,您也可以调用file.flush()在打印后,例如,使用Python 2中的print语句:

import sys
print 'delayed output'
sys.stdout.flush()

Changing the default in one module to flush=True

You can change the default for the print function by using functools.partial on the global scope of a module:

您可以使用功能工具来更改打印功能的默认值。部分关于模块的全局范围:

import functools
print = functools.partial(print, flush=True)

if you look at our new partial function, at least in Python 3:

如果你看一下我们的新部分函数,至少在Python 3中:

>>> print = functools.partial(print, flush=True)
>>> print
functools.partial(<built-in function print>, flush=True)

We can see it works just like normal:

我们可以看到它正常运行:

>>> print('foo')
foo

And we can actually override the new default:

我们可以重写新的默认值:

>>> print('foo', flush=False)
foo

Note again, this only changes the current global scope, because the print name on the current global scope will overshadow the builtin print function (or dereference the compatibility function, if using Python 2, in that current global scope).

请再次注意,这只会改变当前全局范围,因为当前全局范围内的打印名称将会覆盖builtin打印函数(如果在当前全局范围内使用Python 2,则取消兼容函数)。

If you want to do this inside a function instead of on a module's global scope, you should give it a different name, e.g.:

如果您想在函数内而不是在模块的全局范围内执行这个操作,您应该给它一个不同的名称,例如:

def foo():
    printf = functools.partial(print, flush=True)
    printf('print stuff like this')

If you declare it a global in a function, you're changing it on the module's global namespace, so you should just put it in the global namespace, unless that specific behavior is exactly what you want.

如果您在函数中声明它是全局的,那么您将在模块的全局命名空间中更改它,因此您应该将它放在全局命名空间中,除非您想要的正是特定的行为。

Changing the default for the process

I think the best option here is to use the -u flag to get unbuffered output.

我认为这里最好的选择是使用-u标志来获得无缓冲输出。

$ python -u script.py

or

$ python -um package.module

From the docs:

从文档:

Force stdin, stdout and stderr to be totally unbuffered. On systems where it matters, also put stdin, stdout and stderr in binary mode.

Force stdin, stdout和stderr完全没有缓冲。在它重要的系统上,也将stdin、stdout和stderr置于二进制模式。

Note that there is internal buffering in file.readlines() and File Objects (for line in sys.stdin) which is not influenced by this option. To work around this, you will want to use file.readline() inside a while 1: loop.

注意,在file.readlines()和File对象(在sys.stdin中为行)中有内部缓冲,而这并不受此选项的影响。为了解决这个问题,您需要在一个while循环中使用file.readline()。

Changing the default for the shell operating environment

You can get this behavior for all python processes in the environment or environments that inherit from the environment if you set the environment variable to a nonempty string:

如果将环境变量设置为非空字符串,则可以在环境或环境中从环境继承所有python进程的行为。

e.g., in Linux or OSX:

在Linux或OSX中:

$ export PYTHONUNBUFFERED=TRUE

or Windows:

或窗口:

C:\SET PYTHONUNBUFFERED=TRUE

from the docs:

从文档:

PYTHONUNBUFFERED

PYTHONUNBUFFERED

If this is set to a non-empty string it is equivalent to specifying the -u option.

如果将此设置为非空字符串,则等效于指定-u选项。


Addendum

Here's the help on the print function from Python 2.7.12 - note that there is no flush argument:

这里是Python 2.7.12的打印函数的帮助——注意没有泛红的参数:

>>> from __future__ import print_function
>>> help(print)
print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout)

    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file: a file-like object (stream); defaults to the current sys.stdout.
    sep:  string inserted between values, default a space.
    end:  string appended after the last value, default a newline.

#5


64  

Also as suggested in this blog one can reopen sys.stdout in unbuffered mode:

正如在本博客中所建议的,我们可以重新打开sys。stdout中无缓冲的模式:

sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

Each stdout.write and print operation will be automatically flushed afterwards.

每个stdout。写入和打印操作之后将自动刷新。

#6


28  

Using the -u command-line switch works, but it is a little bit clumsy. It would mean that the program would potentially behave incorrectly if the user invoked the script without the -u option. I usually use a custom stdout, like this:

使用-u命令行开关工作,但是有点笨拙。这意味着如果用户在没有-u选项的情况下调用脚本,程序可能会出现错误。我通常使用定制的stdout,像这样:

class flushfile(object):
  def __init__(self, f):
    self.f = f

  def write(self, x):
    self.f.write(x)
    self.f.flush()

import sys
sys.stdout = flushfile(sys.stdout)

... Now all your print calls (which use sys.stdout implicitly), will be automatically flushed.

…现在所有打印调用(使用sys)。stdout隐式),将自动刷新。

#7


19  

With Python 3.x they extended the print() function:

Python 3。他们扩展了print()函数:

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

打印(*对象,sep=', end='\n', file=sys。stdout,冲洗= False)

So, you can just do:

所以,你可以这样做:

print("Visiting toilet", flush=True)

打印(“去厕所”,冲洗= True)


Python Docs Entry

Python文档条目

#8


17  

Why not try using an unbuffered file?

为什么不尝试使用一个无缓冲文件呢?

f = open('xyz.log', 'a', 0)

OR

sys.stdout = open('out.log', 'a', 0)

#9


12  

import sys
print 'This will be output immediately.'
sys.stdout.flush()

#10


11  

Dan's idea doesn't quite work:

丹的想法并不奏效:

#!/usr/bin/env python
class flushfile(file):
    def __init__(self, f):
        self.f = f
    def write(self, x):
        self.f.write(x)
        self.f.flush()

import sys
sys.stdout = flushfile(sys.stdout)

print "foo"

The result:

结果:

Traceback (most recent call last):
  File "./passpersist.py", line 12, in <module>
    print "foo"
ValueError: I/O operation on closed file

I believe the problem is that it inherits from the file class, which actually isn't necessary. According to the docs for sys.stdout:

我认为问题在于它继承了文件类,而这实际上是不必要的。根据sys.stdout的文档:

stdout and stderr needn’t be built-in file objects: any object is acceptable as long as it has a write() method that takes a string argument.

stdout和stderr不必是内置的文件对象:只要它有一个写()方法来接受字符串参数,任何对象都是可以接受的。

so changing

所以改变

class flushfile(file):

to

class flushfile(object):

makes it work just fine.

让它工作得很好。

#11


6  

Here is my version, which provides writelines() and fileno(), too:

以下是我的版本,提供了writelines()和fileno():

class FlushFile(object):
    def __init__(self, fd):
        self.fd = fd

    def write(self, x):
        ret = self.fd.write(x)
        self.fd.flush()
        return ret

    def writelines(self, lines):
        ret = self.writelines(lines)
        self.fd.flush()
        return ret

    def flush(self):
        return self.fd.flush

    def close(self):
        return self.fd.close()

    def fileno(self):
        return self.fd.fileno()

#12


5  

Loved Dan's solution! For python3 do:

爱丹的解决方案!python3做:

import io,sys
class flushfile:
    def __init__(self, f):
        self.f = f
    def write(self, x):
        self.f.write(x)
        self.f.flush()
sys.stdout = flushfile(sys.stdout)

#13


2  

In Python 3 you can overwrite print function with default set to flush = True

在Python 3中,您可以使用默认设置来覆盖print函数。

def print(*objects, sep=' ', end='\n', file=sys.stdout, flush=True):
    __builtins__.print(*objects, sep=sep, end=end, file=file, flush=flush)

#14


2  

I did it like this in Python 3.4:

我在python3.4中这样做了

'''To write to screen in real-time'''
message = lambda x: print(x, flush=True, end="")
message('I am flushing out now...')