Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

clean shutdown of listener #234

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

klahnakoski
Copy link

This is a proposed change to ensure the Flask server can be shutdown without bringing down the whole process.

Comment on lines -116 to +130
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)
Copy link
Author

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.

Copy link
Author

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

Comment on lines 232 to 248
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:
...
Copy link
Author

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

Comment on lines +224 to +225
is_done.set()
threading.Timer(2, server.shutdown).start()
Copy link
Author

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()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

login() will actually return

klahnakoski added a commit to klahnakoski/mozilla-aws-cli-mozilla that referenced this pull request Aug 11, 2020
@klahnakoski klahnakoski marked this pull request as ready for review August 19, 2020 11:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant