-
Notifications
You must be signed in to change notification settings - Fork 6
clean shutdown of listener #234
base: master
Are you sure you want to change the base?
Conversation
start = time.time() | ||
while time.time() - start < 30: | ||
if login.last_state_check is None: | ||
pass | ||
elif (time.time() - login.last_state_check > | ||
login.max_sleep_no_state_check): | ||
logger.error( | ||
"No response from web interface for {} seconds, shutting " | ||
"down.".format(login.max_sleep_no_state_check)) | ||
exit_sigint() | ||
time.sleep(0.5) | ||
# start = time.time() | ||
# while time.time() - start < 30: | ||
# if login.last_state_check is None: | ||
# pass | ||
# elif (time.time() - login.last_state_check > | ||
# login.max_sleep_no_state_check): | ||
# logger.error( | ||
# "No response from web interface for {} seconds, shutting " | ||
# "down.".format(login.max_sleep_no_state_check)) | ||
# exit_sigint() | ||
# time.sleep(0.5) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will require guidance here: This 2 second response time is too strict on my machine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...plus it seems to delay response for 30 seconds
mozilla_aws_cli/listener.py
Outdated
class ServerThread(threading.Thread): | ||
|
||
def __init__(self, app): | ||
threading.Thread.__init__(self) | ||
self.srv = make_server('127.0.0.1', port, app) | ||
self.ctx = app.app_context() | ||
self.ctx.push() | ||
|
||
def run(self): | ||
self.srv.serve_forever() | ||
logger.debug("Flask done") | ||
|
||
def shutdown(self): | ||
try: | ||
self.srv.shutdown() | ||
except Exception: | ||
... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We make a server so we have shutdown control
is_done.set() | ||
threading.Timer(2, server.shutdown).start() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call shutdown in a couple of seconds. This could be shorter time, if we know more about how long the shutdown response takes to be delivered.
|
||
server = ServerThread(app) | ||
server.start() | ||
is_done.wait() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
login()
will actually return
This is a proposed change to ensure the Flask server can be shutdown without bringing down the whole process.