Browse Source

reboot running port in case of execute cmd+z

pull/1711/head
erkanay 9 years ago
parent
commit
45977dc26a
  1. 24
      flask/app.py

24
flask/app.py

@ -779,6 +779,30 @@ class Flask(_PackageBoundObject):
rv.update(processor())
return rv
def reboot(self):
"""A decorator that is used to terminate running port
by application.
@app.reboot()
@app.route('/')
def index():
return 'Hello World'
"""
def decorator(f):
import re
import commands
s = commands.getoutput('lsof -i :5000')
try:
p_id = re.findall('.*?Python\s+[0-9]{4,7}', s)[0].split(' ')[-1]
except IndexError:
p_id = None
p_id = int(p_id) if p_id else None
if p_id:
commands.getoutput('kill -9 {}'.format(p_id))
return f
return decorator
def run(self, host=None, port=None, debug=None, **options):
"""Runs the application on a local development server. If the
:attr:`debug` flag is set the server will automatically reload

Loading…
Cancel
Save