-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging instead of print #860
base: master
Are you sure you want to change the base?
Changes from 1 commit
092545e
953d1ce
138da74
04fbdbb
34ce206
c611197
cea7db2
63e3d4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
"""Classes to instantiate and manage the life cycle of the nengo_gui | ||
backend.""" | ||
|
||
import logging | ||
from __future__ import print_function | ||
|
||
import select | ||
|
@@ -13,6 +14,9 @@ | |
from nengo_gui.guibackend import GuiServer | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ServerShutdown(Exception): | ||
"""Causes the server to shutdown when raised.""" | ||
pass | ||
|
@@ -70,25 +74,26 @@ class InteractiveGUI(BaseGUI): | |
|
||
def start(self): | ||
protocol = 'https:' if self.server.settings.use_ssl else 'http:' | ||
print("Starting nengo server at %s//%s:%d" % | ||
(protocol, 'localhost', self.server.server_port)) | ||
logger.info("Starting nengo server at %s//%s:%d", | ||
protocol, 'localhost', self.server.server_port) | ||
|
||
if not sys.platform.startswith('win'): | ||
signal.signal(signal.SIGINT, self._confirm_shutdown) | ||
|
||
try: | ||
self.server.serve_forever(poll_interval=0.02) | ||
print("No connections remaining to the nengo_gui server.") | ||
logger.info("No connections remaining to the nengo_gui server.") | ||
except ServerShutdown: | ||
self.server.shutdown() | ||
finally: | ||
print("Shutting down server...") | ||
logger.info("Shutting down server...") | ||
|
||
self.server.wait_for_shutdown(0.05) | ||
n_zombie = sum(thread.is_alive() | ||
for thread, _ in self.server.requests) | ||
if n_zombie > 0: | ||
print("%d zombie threads will close abruptly" % n_zombie) | ||
logger.warning("%d zombie threads will close abruptly", | ||
n_zombie) | ||
|
||
def _confirm_shutdown(self, signum, frame): | ||
signal.signal(signal.SIGINT, self._immediate_shutdown) | ||
|
@@ -100,9 +105,9 @@ def _confirm_shutdown(self, signum, frame): | |
if line[0].lower() == 'y': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These last two There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I might argue that the other |
||
raise ServerShutdown() | ||
else: | ||
print("Resuming...") | ||
logger.info("Resuming...") | ||
else: | ||
print("No confirmation received. Resuming...") | ||
logger.info("No confirmation received. Resuming...") | ||
signal.signal(signal.SIGINT, self._confirm_shutdown) | ||
|
||
def _immediate_shutdown(self, signum, frame): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,12 @@ | |
from nengo_gui.password import gensalt, hashpw, prompt_pw | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should always be visible to the user and not end up in some log file. Thus, it should stay a |
||
def old_main(): | ||
print("'nengo_gui' has been renamed to 'nengo'.") | ||
print("Please run 'nengo' in the future to avoid this message!\n") | ||
logger.info("'nengo_gui' has been renamed to 'nengo'.") | ||
logger.info("Please run 'nengo' in the future to avoid this message!\n") | ||
main() | ||
|
||
|
||
|
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'd probably make this a
debug
message. It isn't really relevant to the user.