Skip to content

Commit 743463d

Browse files
committed
Execute shutdown function before running update to avoid segfault on linux
1 parent 0b04176 commit 743463d

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

zeronet.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/usr/bin/env python3
2-
3-
# Included modules
42
import os
53
import sys
64

@@ -35,13 +33,20 @@ def main():
3533

3634
if main and (main.update_after_shutdown or main.restart_after_shutdown): # Updater
3735
if main.update_after_shutdown:
36+
print("Shutting down...")
37+
prepareShutdown()
3838
import update
39+
print("Updating...")
3940
update.update()
41+
print("Restarting...")
4042
restart()
4143
else:
44+
print("Shutting down...")
45+
prepareShutdown()
4246
print("Restarting...")
4347
restart()
4448

49+
4550
def displayErrorMessage(err, error_log_path):
4651
import ctypes
4752
import urllib.parse
@@ -64,22 +69,23 @@ def displayErrorMessage(err, error_log_path):
6469
if res in [ID_YES, ID_NO]:
6570
subprocess.Popen(['notepad.exe', error_log_path])
6671

72+
def prepareShutdown():
73+
import atexit
74+
atexit._run_exitfuncs()
6775

68-
def restart():
76+
# Close log files
6977
if "main" in sys.modules:
70-
import atexit
71-
# Close log files
7278
logger = sys.modules["main"].logging.getLogger()
7379

7480
for handler in logger.handlers[:]:
7581
handler.flush()
7682
handler.close()
7783
logger.removeHandler(handler)
7884

79-
atexit._run_exitfuncs()
80-
import time
81-
time.sleep(1) # Wait files to close
85+
import time
86+
time.sleep(1) # Wait files to close
8287

88+
def restart():
8389
args = sys.argv[:]
8490

8591
sys.executable = sys.executable.replace(".pkg", "") # Frozen mac fix

0 commit comments

Comments
 (0)