From 864a7b1e2f4781735585d5516ade555d11d839c4 Mon Sep 17 00:00:00 2001 From: luav Date: Mon, 20 Aug 2018 10:41:44 +0200 Subject: [PATCH] Timestamp header for the piped output logging fixed --- mpepool.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mpepool.py b/mpepool.py index 5db657d..3462c10 100755 --- a/mpepool.py +++ b/mpepool.py @@ -1145,11 +1145,11 @@ def complete(self, graceful=None): os.makedirs(plog) # Append to the file flog = None + timestamp = None try: - # Add a timestamp if the file is not empty to distinguish logs - timestamp = None flog = plog if not isinstance(plog, str) else open(plog, 'a') - if os.fstat(flog.fileno()).st_size: + # Add a timestamp if the file is not empty to distinguish logs + if isinstance(plog, str) and os.fstat(flog.fileno()).st_size: if timestamp is None: timestamp = time.gmtime() except IOError as err: @@ -1160,7 +1160,8 @@ def complete(self, graceful=None): if pout is self.pipedout: flog = sys.stdout try: - print(timeheader(timestamp), file=flog) # Note: prints also newline unlike flog.write() + if timestamp is not None: + print(timeheader(timestamp), file=flog) # Note: prints also newline unlike flog.write() flog.write(pout) # Write the piped output except IOError as err: print('ERROR on logging piped data "{}" for "{}": {}'