Skip to content

Conversation

@iquintero
Copy link
Contributor

For Serving containers the container would start as a child process
using Popen, the stdout/stderr are sent to the terminal as usual,
however on Jupyter notebooks this does not happen because Jupyter does
not show the output of child processes.

This instroduces a Thread that prints the output from a subprocess PIPE.
By doing this, the output comes from the main process and will be shown
in Jupyter notebooks.

Issue #, if available:

Description of changes:

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have updated the changelog with a description of my changes (if appropriate)
  • I have updated any necessary documentation (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@iquintero iquintero requested a review from owen-t May 30, 2018 00:06
For Serving containers the container would start as a child process
using Popen, the stdout/stderr are sent to the terminal as usual,
however on Jupyter notebooks this does not happen because Jupyter does
not show the output of child processes.

This instroduces a Thread that prints the output from a subprocess PIPE.
By doing this, the output comes from the main process and will be shown
in Jupyter notebooks.
@codecov-io
Copy link

codecov-io commented May 30, 2018

Codecov Report

Merging #203 into master will decrease coverage by 0.23%.
The diff coverage is 78.94%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #203      +/-   ##
==========================================
- Coverage   91.03%   90.79%   -0.24%     
==========================================
  Files          42       42              
  Lines        2699     2717      +18     
==========================================
+ Hits         2457     2467      +10     
- Misses        242      250       +8
Impacted Files Coverage Δ
src/sagemaker/local/image.py 86.07% <78.94%> (-1.85%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8560f37...81a02f3. Read the comment docs.

@iquintero iquintero force-pushed the lm_log_improvement branch from 654ee0e to 9d92345 Compare May 30, 2018 00:30
# _stream_output() doesn't have the command line. We will handle the exception
# which contains the exit code and append the command line to it.
msg = "Failed to run: %s, %s" % (compose_command, e.message)
raise RuntimeError(msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

can you also include e as well

def __init__(self, command, startup_delay=5):
class _HostingContainer(Thread):
def __init__(self, command):
Thread.__init__(self)
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay if Thread isn't a new style class.

def up(self):
self.process = Popen(self.command)
sleep(self.startup_delay)
def run(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

This is identical to the code in train, just with a different command. Suggest refactoring into a utility function.

process = subprocess.Popen(compose_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

try:
_stream_output(process)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need this.

Doesn't something like this work:

>>> subprocess.check_call(["ls", "asdf"], stderr=sys.stdout.fileno())
ls: asdf: No such file or directory
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 186, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['ls', 'asdf']' returned non-zero exit status 1

I think the interface is a bit different in python 3, but we can work through this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Talked IRL, this won't work in Jupyter because Jupyter replaces the stderr object.

@iquintero iquintero merged commit f132882 into aws:master May 30, 2018
@iquintero iquintero deleted the lm_log_improvement branch June 7, 2018 21:38
apacker pushed a commit to apacker/sagemaker-python-sdk that referenced this pull request Nov 15, 2018
Fixed: Seq2seq misnamed sagemaker client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants