squash bug in closing Flask web server (fixes #131)

This commit is contained in:
Micah Lee 2014-09-03 00:11:15 -07:00
parent 17646641f6
commit 2c1534979e
2 changed files with 11 additions and 14 deletions

View File

@ -195,17 +195,14 @@ def start(port, stay_open=False):
set_stay_open(stay_open)
app.run(port=port)
def stop():
def stop(port):
# to stop flask, load http://127.0.0.1:<port>/<shutdown_slug>/shutdown
try:
if helpers.get_platform() == 'Tails':
# in Tails everything is proxies over Tor, so we need to get lower level
# to connect not over the proxy
import socket
s = socket.socket()
s.connect(('127.0.0.1', app.port))
s.sendall('GET /{0}/shutdown HTTP/1.1\r\n\r\n'.format(shutdown_slug))
else:
urllib2.urlopen('http://127.0.0.1:{0}/{1}/shutdown'.format(app.port, shutdown_slug)).read()
except:
pass
if helpers.get_platform() == 'Tails':
# in Tails everything is proxies over Tor, so we need to get lower level
# to connect not over the proxy
import socket
s = socket.socket()
s.connect(('127.0.0.1', port))
s.sendall('GET /{0}/shutdown HTTP/1.1\r\n\r\n'.format(shutdown_slug))
else:
urllib2.urlopen('http://127.0.0.1:{0}/{1}/shutdown'.format(port, shutdown_slug)).read()

View File

@ -138,7 +138,7 @@ class OnionShareGui(QtGui.QWidget):
t.start()
def stop_server(self):
web.stop()
web.stop(self.app.port)
self.app.cleanup()
self.stop_server_finished.emit()