From 479bfe58eb521ee56780a37a781c78ab1057ab2c Mon Sep 17 00:00:00 2001 From: Athanasius Date: Tue, 19 Jan 2021 12:39:32 +0000 Subject: [PATCH] Log truncate outside the 'else' & misc logging cleanups and comments * The "truncate the stdout redirect" code was erroneously inside the else of a try. * Added some comments about exceptions found on Linux when unable to open the journals_dir lock file * Changed 'assuming another process running' logging to not split lines. * "Couldn't open " isn't inside no_other_instances() so made the message more obvious. --- EDMarketConnector.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index ee424583..ccfdce35 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -84,7 +84,7 @@ if __name__ == '__main__': # noqa: C901 except Exception as e: logger.info(f"Exception: Couldn't lock journal directory \"{journal_dir}\"" - f", assuming another process running\n{e!r}") + f", assuming another process running: {e!r}") locked = True if locked: @@ -183,7 +183,7 @@ if __name__ == '__main__': # noqa: C901 except Exception as e: logger.info(f"Exception: Couldn't lock journal directory \"{journal_dir}\"," - f"assuming another process running\n{e!r}") + f"assuming another process running: {e!r}") return False journal_dir_lockfile.write(f"Path: {journal_dir}\nPID: {os_getpid()}\n") @@ -221,9 +221,11 @@ if __name__ == '__main__': # noqa: C901 try: journal_dir_lockfile = open(journal_dir_lockfile_name, mode='w+', encoding='utf-8') + # Linux CIFS read-only mount throws: OSError(30, 'Read-only file system') + # Linux no-write-perm directory throws: PermissionError(13, 'Permission denied') except Exception as e: # For remote FS this could be any of a wide range of exceptions logger.warning(f"Couldn't open \"{journal_dir_lockfile_name}\" for \"w+\"" - f"Aborting checks: {e!r}") + f" Aborting duplicate process checks: {e!r}") else: if not no_other_instance_running(): @@ -237,9 +239,9 @@ if __name__ == '__main__': # noqa: C901 # reach here. sys.exit(0) - if getattr(sys, 'frozen', False): - # Now that we're sure we're the only instance running we can truncate the logfile - sys.stdout.truncate() + if getattr(sys, 'frozen', False): + # Now that we're sure we're the only instance running we can truncate the logfile + sys.stdout.truncate() # See EDMCLogging.py docs.