refactored cleanup handlers to use a queue, so they will work with the GUI

This commit is contained in:
Micah Lee 2014-08-26 15:44:44 -07:00
parent a3fb7a930b
commit 0bc778437d
3 changed files with 22 additions and 13 deletions

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue, inspect, base64, mimetypes, hmac import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue, inspect, base64, mimetypes, hmac, shutil
from itertools import izip from itertools import izip
from stem.control import Controller from stem.control import Controller
@ -92,6 +92,22 @@ def add_request(type, path, data=None):
'data': data 'data': data
}) })
cleanup_q = Queue.Queue()
def register_cleanup_handler(directory):
global cleanup_q
def handler(signum = None, frame = None):
shutil.rmtree(directory)
cleanup_q.put(handler)
def execute_cleanup_handlers():
global cleanup_q
try:
while True:
handler = cleanup_q.get(False)
handler()
except Queue.Empty:
pass
def human_readable_filesize(b): def human_readable_filesize(b):
thresh = 1024.0 thresh = 1024.0
if b < thresh: if b < thresh:
@ -305,16 +321,6 @@ def tails_root():
while True: while True:
time.sleep(1) time.sleep(1)
def register_cleanup_handler(directory):
import signal
import shutil
def handler(signum = None, frame = None):
shutil.rmtree(directory)
sys.exit()
for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]:
signal.signal(sig, handler)
def main(): def main():
load_strings() load_strings()
tails_root() tails_root()
@ -383,5 +389,8 @@ def main():
app.run(port=port) app.run(port=port)
print '\n' print '\n'
# shutdown
execute_cleanup_handlers()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -373,7 +373,7 @@ def main():
# clean up when app quits # clean up when app quits
def shutdown(): def shutdown():
pass onionshare.execute_cleanup_handlers()
app.connect(app, QtCore.SIGNAL("aboutToQuit()"), shutdown) app.connect(app, QtCore.SIGNAL("aboutToQuit()"), shutdown)
# launch the gui # launch the gui

View File

@ -1,5 +1,5 @@
from __future__ import division from __future__ import division
import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue, inspect, base64, random, functools, logging, ctypes, hmac import os, sys, subprocess, time, hashlib, platform, json, locale, socket, argparse, Queue, inspect, base64, random, functools, logging, ctypes, hmac, shutil
from itertools import izip from itertools import izip
import stem, stem.control, flask import stem, stem.control, flask
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui