mirror of https://github.com/nicolargo/glances.git
Standard output misbehaviour (need to flush) #1376
This commit is contained in:
parent
162ed83986
commit
f0917c0c62
1
NEWS
1
NEWS
|
|
@ -24,6 +24,7 @@ Bugs corrected:
|
|||
* Support for monochrome (serial) terminals e.g. vt220 #1362
|
||||
* TypeError on opening (Wifi plugin) #1373
|
||||
* Some field name are incorrect in CSV export #1372
|
||||
* Standard output misbehaviour (need to flush) #1376
|
||||
|
||||
Others:
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
# pylint: skip-file
|
||||
"""Python 2/3 compatibility shims."""
|
||||
|
||||
from __future__ import print_function
|
||||
import operator
|
||||
import sys
|
||||
import unicodedata
|
||||
|
|
@ -54,6 +55,10 @@ if PY3:
|
|||
viewvalues = operator.methodcaller('values')
|
||||
viewitems = operator.methodcaller('items')
|
||||
|
||||
def printandflush(string):
|
||||
"""Print and flush (used by stdout* outputs modules)"""
|
||||
print(string, flush=True)
|
||||
|
||||
def to_ascii(s):
|
||||
"""Convert the bytes string to a ASCII string
|
||||
Usefull to remove accent (diacritics)"""
|
||||
|
|
@ -126,6 +131,11 @@ else:
|
|||
viewvalues = operator.methodcaller('viewvalues')
|
||||
viewitems = operator.methodcaller('viewitems')
|
||||
|
||||
def printandflush(string):
|
||||
"""Print and flush (used by stdout* outputs modules)"""
|
||||
print(string)
|
||||
sys.stdout.flush()
|
||||
|
||||
def mean(numbers):
|
||||
return float(sum(numbers)) / max(len(numbers), 1)
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
import time
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.compat import printandflush
|
||||
|
||||
|
||||
class GlancesStdout(object):
|
||||
|
|
@ -70,13 +71,13 @@ class GlancesStdout(object):
|
|||
if attribute is not None:
|
||||
# With attribute
|
||||
try:
|
||||
print("{}.{}: {}".format(plugin, attribute,
|
||||
stat[attribute]))
|
||||
printandflush("{}.{}: {}".format(plugin, attribute,
|
||||
stat[attribute]))
|
||||
except KeyError as err:
|
||||
logger.error("Can not display stat {}.{} ({})".format(plugin, attribute, err))
|
||||
else:
|
||||
# Without attribute
|
||||
print("{}: {}".format(plugin, stat))
|
||||
printandflush("{}: {}".format(plugin, stat))
|
||||
|
||||
# Wait until next refresh
|
||||
if duration > 0:
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
import time
|
||||
|
||||
from glances.logger import logger
|
||||
from glances.compat import printandflush
|
||||
|
||||
|
||||
class GlancesStdoutCsv(object):
|
||||
|
|
@ -128,7 +129,7 @@ class GlancesStdoutCsv(object):
|
|||
line += self.build_data(plugin, attribute, stat)
|
||||
|
||||
# Display the line (without the last 'separator')
|
||||
print(line[:-1])
|
||||
printandflush(line[:-1])
|
||||
|
||||
# Display header one time
|
||||
self.header = False
|
||||
|
|
|
|||
Loading…
Reference in New Issue