Delete the lock file on Ctrl-C

This commit is contained in:
Micah Lee 2020-04-06 20:19:35 -07:00
parent ea1b430aea
commit 7ef1dfbe9c
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73

View File

@ -64,10 +64,6 @@ def main():
# Display OnionShare banner # Display OnionShare banner
print(f"OnionShare {common.version} | https://onionshare.org/") print(f"OnionShare {common.version} | https://onionshare.org/")
# Allow Ctrl-C to smoothly quit the program instead of throwing an exception
# https://stackoverflow.com/questions/42814093/how-to-handle-ctrlc-in-python-app-with-pyqt
signal.signal(signal.SIGINT, signal.SIG_DFL)
# Start the Qt app # Start the Qt app
global qtapp global qtapp
qtapp = Application(common) qtapp = Application(common)
@ -147,6 +143,15 @@ def main():
with open(common.gui.lock_filename, "w") as f: with open(common.gui.lock_filename, "w") as f:
f.write(f"{os.getpid()}\n") f.write(f"{os.getpid()}\n")
# Allow Ctrl-C to smoothly quit the program instead of throwing an exception
def signal_handler(s, frame):
print("\nCtrl-C pressed, quitting")
if os.path.exists(common.gui.lock_filename):
os.remove(common.gui.lock_filename)
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
# Launch the gui # Launch the gui
main_window = MainWindow(common, filenames) main_window = MainWindow(common, filenames)