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

Conversation

sahilshekhawat
Copy link
Member

Fixes #232

  • There are no merge conflicts.
  • If there is a related issue, a reference to that issue is in the
    commit message.
  • Unit tests have been added for the bug. (Please reference the issue #
    in the unit test.)
  • The tests pass both locally (run nosetests) and on Travis CI.
  • The code follows PEP8 guidelines. (use a linter, e.g.
    pylint, to check your code)
  • The bug fix is documented in the Release
    Notes
    .
  • The code is backwards compatible. (All public methods/classes must
    follow deprecation cycles.)
  • All reviewer comments have been addressed.

@sahilshekhawat
Copy link
Member Author

@pydy/pydy-developers This needs a review. Should be a quick one.

@@ -1,37 +1,107 @@
#!/usr/bin/env python

from __future__ import print_function
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't do this. Just make sure to use parentheses on all print statements.

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

Required by signal.signal

"""
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!

@moorepants
Copy link
Member

Is there any way to have unit tests for this?

@moorepants moorepants added this to the 0.3.0 Release milestone Jun 17, 2015
"""
res = raw_input("Shutdown this visualization server ([y]/n)? ")
res = res.lower()[0:1]
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"

def __init__(self, port=8000, scene_file="Null"):
self.port = port
self.scene_file = scene_file
self.directory = "static/"
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this should be pass in as an argument.

@sahilshekhawat
Copy link
Member Author

Should I create a custom error for empty scene_file?

@moorepants
Copy link
Member

i don't think that is necessary. if the user passes in a scene_file that isn't a valid valid file name there will be some other errors that raise, no?

@sahilshekhawat
Copy link
Member Author

it is for an empty scene file name.

@moorepants
Copy link
Member

What do you mean by empty?

@sahilshekhawat
Copy link
Member Author

When user does not pass the scene_file to the server. We should raise an error, no?

@moorepants
Copy link
Member

If your docstring says:

scene_file : string
    A valid path to a file in the ``directory``.

Then you can use the "garbage in, garbage out" rule.

@moorepants
Copy link
Member

If the user doesn't pass in a required argument they will get an error from Python that says they are missing an argument.

def _check_port(self, port):
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = soc.connect_ex(('127.0.0.1', port))
if result == 0:
Copy link
Contributor

Choose a reason for hiding this comment

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

return result == 0

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@sahilshekhawat
Copy link
Member Author

@oliverlee Can you please review this PR. It needs to be merged before my other PR can be reviewed.

run_server()
"""
res = raw_input("Shutdown this visualization server ([y]/n)? ")
res = res.lower()[0:1]
Copy link
Contributor

Choose a reason for hiding this comment

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

res.lower()[0] can be used instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup! changing.

@sahilshekhawat
Copy link
Member Author

I have addressed all the concerns here. It would be very helpful if someone can please review it. I think it can be merged. Thanks


__all__ = ['run_server']
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.

@moorepants
Copy link
Member

I'm merging this without tests. I'll raise an issue to fix that.

moorepants added a commit that referenced this pull request Jun 18, 2015
Added shutting down calls to the visualization server
@moorepants moorepants merged commit 756f80a into pydy:master Jun 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean exit of server
3 participants