From ae76a0daf52e79bd617a35b29b2cb912f7d7f674 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sun, 29 May 2022 03:26:20 +0200 Subject: [PATCH] windows binaries: try to prevent users from renaming exe while running closes https://github.com/spesmilo/electrum/issues/4072 (this fix AFAICT only works on Windows, and #4072 contains some macOS reports as well, however all recent reports are for Windows and overall most reports are for Windows, so let's close it optimistically for now) --- run_electrum | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/run_electrum b/run_electrum index d6a0daf2e..4dd1cc146 100755 --- a/run_electrum +++ b/run_electrum @@ -56,6 +56,12 @@ if is_git_clone: if is_local or is_android: sys.path.insert(0, os.path.join(script_dir, 'packages')) +if is_pyinstaller: + # Keep an open file handle for the binary that started us. On Windows, this + # prevents users from moving or renaming the exe file while running (doing which + # causes ImportErrors and other runtime failures). (see #4072) + _file = open(sys.executable, 'rb') + def check_imports(): # pure-python dependencies need to be imported here for pyinstaller