Skip to content
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

Added shutting down calls to the visualization server #241

Merged
merged 13 commits into from
Jun 18, 2015
Merged
Prev Previous commit
Next Next commit
Addressed some minor fixes in pydy-viz server
  • Loading branch information
sahilshekhawat committed Jun 18, 2015
commit 63756c3ec3fa78e4b4ecb4b1df0004876a39280e
11 changes: 6 additions & 5 deletions pydy/viz/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ class Server(object):
Parameters
----------
port : integer
Defines the port on which the server will run.
Defines the port on which the server will run. If this port is
already bind, then it increment 1 until it finds a free port.
scene_file : name of the scene_file generated for visualization
A Valid PyDy generated scene file in 'directory'.
A Valid PyDy generated scene file in 'directory' parameter.
directory : absolute path of a directory
Absolute path to the directory which contains scene_file with
all other static files.
Expand All @@ -73,12 +74,12 @@ class Server(object):
def __init__(self, scene_file, directory=None, port=None):
self.scene_file = scene_file
Copy link
Member

Choose a reason for hiding this comment

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

My suggestion in the previous commit was to have this call sig:

def __init__(scene_file, directory=None, port=8000)

The scene file should be required and the directory can default to the cwd if None is passed in.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will add that in my new pr on static directory creation. Trying to make it atomic

Copy link
Member

Choose a reason for hiding this comment

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

But this is a whole new server code. It seems atomic to add this.


if directory:
if directory is None:
self.directory = directory
else:
self.directory = "static/"

if port:
if port is None:
Copy link
Member

Choose a reason for hiding this comment

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

If you have a default value for port and directory you should just set it in the call signature:

def __init__(self, scene_file, directory='static', port=8000):

Sorry if I've confused you about this.

Copy link
Member

Choose a reason for hiding this comment

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

But, I don't see how using directory='static' is a good idea. That's why I suggested using directory=None and then if that was true setting directory = os.getcwd().

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay , I am updating it.
Static directory gets created in current working directory itself.

self.port = port
else:
self.port = 8000
Expand Down Expand Up @@ -121,7 +122,7 @@ def _stop_server(self, signal, frame):

"""
res = raw_input("Shutdown this visualization server ([y]/n)? ")
Copy link
Member

Choose a reason for hiding this comment

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

This will fail in Python 3. Oliver had the fix for this in this file before this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

What are the options then, should I use input()?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it!

res = res.lower()[0:1]
res = res.lower()[0]
if res == '' or res == 'y':
Copy link
Member Author

Choose a reason for hiding this comment

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

This works even for strings like "Yes"

print("Shutdown confirmed")
print("Shutting down server...")
Expand Down