partial cleanup of zeronet.py

This commit is contained in:
Matthew Bell 2015-06-17 22:31:38 +01:00
parent adcee874db
commit d45e162e7f
1 changed files with 46 additions and 39 deletions

View File

@ -1,49 +1,56 @@
#!/usr/bin/env python
# Included modules
import os
import gc
import sys
import traceback
# ZeroNet Modules
import update
def main():
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
print "- Starting ZeroNet..."
# Update
update.update()
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
# 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
logger = sys.modules["main"].logging.getLogger()
# Update
update.update()
for handler in logger.handlers[:]:
handler.flush()
handler.close()
logger.removeHandler(handler)
# Close log files
logger = sys.modules["main"].logging.getLogger()
except Exception, err: # Prevent closing
import traceback
traceback.print_exc()
traceback.print_exc(file=open("log/error.log", "a"))
for handler in logger.handlers[:]:
handler.flush()
handler.close()
logger.removeHandler(handler)
if main and main.update_after_shutdown: # Updater
# Restart
gc.collect() # Garbage collect
print "Restarting..."
args = sys.argv[:]
args.insert(0, sys.executable)
if sys.platform == 'win32':
args = ['"%s"' % arg for arg in args]
os.execv(sys.executable, args)
print "Bye."
except (Exception, ): # Prevent closing
traceback.print_exc()
traceback.print_exc(file=open("log/error.log", "a"))
if main and main.update_after_shutdown: # Updater
# Restart
gc.collect() # Garbage collect
print "Restarting..."
args = sys.argv[:]
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__':
main()
main()