partial cleanup of zeronet.py
This commit is contained in:
parent
adcee874db
commit
d45e162e7f
1 changed files with 46 additions and 39 deletions
85
zeronet.py
85
zeronet.py
|
@ -1,49 +1,56 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# Included modules
|
||||||
|
import os
|
||||||
|
import gc
|
||||||
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
# ZeroNet Modules
|
||||||
|
import update
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print "- Starting ZeroNet..."
|
print "- Starting ZeroNet..."
|
||||||
import sys, os
|
|
||||||
main = None
|
|
||||||
try:
|
|
||||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) # Imports relative to src
|
|
||||||
import main
|
|
||||||
main.start()
|
|
||||||
if main.update_after_shutdown: # Updater
|
|
||||||
import update, sys, os, gc
|
|
||||||
# Try cleanup openssl
|
|
||||||
try:
|
|
||||||
if "lib.opensslVerify" in sys.modules:
|
|
||||||
sys.modules["lib.opensslVerify"].opensslVerify.closeLibrary()
|
|
||||||
except Exception, err:
|
|
||||||
print "Error closing openssl", err
|
|
||||||
|
|
||||||
# Update
|
main = None
|
||||||
update.update()
|
try:
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src")) # Imports relative to src
|
||||||
|
import main
|
||||||
|
main.start()
|
||||||
|
if main.update_after_shutdown: # Updater
|
||||||
|
# Try cleanup openssl
|
||||||
|
try:
|
||||||
|
if "lib.opensslVerify" in sys.modules:
|
||||||
|
sys.modules["lib.opensslVerify"].opensslVerify.closeLibrary()
|
||||||
|
except Exception, err:
|
||||||
|
print "Error closing openssl", err
|
||||||
|
|
||||||
# Close log files
|
# Update
|
||||||
logger = sys.modules["main"].logging.getLogger()
|
update.update()
|
||||||
|
|
||||||
for handler in logger.handlers[:]:
|
# Close log files
|
||||||
handler.flush()
|
logger = sys.modules["main"].logging.getLogger()
|
||||||
handler.close()
|
|
||||||
logger.removeHandler(handler)
|
|
||||||
|
|
||||||
except Exception, err: # Prevent closing
|
for handler in logger.handlers[:]:
|
||||||
import traceback
|
handler.flush()
|
||||||
traceback.print_exc()
|
handler.close()
|
||||||
traceback.print_exc(file=open("log/error.log", "a"))
|
logger.removeHandler(handler)
|
||||||
|
|
||||||
if main and main.update_after_shutdown: # Updater
|
except (Exception, ): # Prevent closing
|
||||||
# Restart
|
traceback.print_exc()
|
||||||
gc.collect() # Garbage collect
|
traceback.print_exc(file=open("log/error.log", "a"))
|
||||||
print "Restarting..."
|
|
||||||
args = sys.argv[:]
|
if main and main.update_after_shutdown: # Updater
|
||||||
args.insert(0, sys.executable)
|
# Restart
|
||||||
if sys.platform == 'win32':
|
gc.collect() # Garbage collect
|
||||||
args = ['"%s"' % arg for arg in args]
|
print "Restarting..."
|
||||||
os.execv(sys.executable, args)
|
args = sys.argv[:]
|
||||||
print "Bye."
|
args.insert(0, sys.executable)
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
args = ['"%s"' % arg for arg in args]
|
||||||
|
os.execv(sys.executable, args)
|
||||||
|
print "Bye."
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue