HomePhabricator

[electrum] suppress an error when sys.stdout is None

Description

[electrum] suppress an error when sys.stdout is None

Summary:
This removes an error dialog that can pop up on Windows when the application is executed without anny stdout attached: "Unhandled execption in script... AtrributeError: 'NoneType' object has no attribute 'write'"

Context: This error was encountered by a Windows user when trying to open Electrum ABC while it was already running. In such a case the application prints "ok" (the return value of server.gui(config_options) to stdout. Luckily this error does not happen in a "normal" scenario (Electrum ABC started only once) every time the gui application is about to be closed , because the print call is preceded by sys.exit(0) . See the electrum-abc::run_gui function

Test Plan:

diff --git a/electrum/electrum-abc b/electrum/electrum-abc
index 9703327c24..ea6e340888 100755
--- a/electrum/electrum-abc
+++ b/electrum/electrum-abc
@@ -398,6 +398,8 @@ def run_gui(config: SimpleConfig, config_options: dict):
             daemon_thread.join(timeout=5.0)
         sys.exit(0)

+    sys.stdout = None
+
     return server.gui(config_options)

With this patch, check that before this diff the error can be reproduced by starting the application in two terminals (python stacktrace printed to the second terminal). After this diff there is no error.

Reviewers: #bitcoin_abc, bytesofman

Reviewed By: #bitcoin_abc, bytesofman

Differential Revision: https://reviews.bitcoinabc.org/D16327

Details

Provenance
PiRKAuthored on Wed, Jun 12, 09:56
PiRKPushed on Wed, Jun 12, 21:09
Reviewer
Restricted Project
Differential Revision
D16327: [electrum] suppress an error when sys.stdout is None
Parents
rABCcf5d866f47b7: [electrum] rework copyright and license files, link it in About dialog
Branches
Unknown
Tags
Unknown