Skip to content

Commit

Permalink
Merge pull request #3593 from ztane/feature/pserve-write-to-stderr
Browse files Browse the repository at this point in the history
Fixing #3592 - output diagnostic messages to stderr, not stdout
  • Loading branch information
mmerickel committed Jun 3, 2020
2 parents 0a9d140 + 2ba260e commit 0ea2378
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ Features
are now importable from the ``pyramid.authorization`` namespace.
See https://github.com/Pylons/pyramid/pull/3563

- ``pserve`` now outputs verbose messaging to `stderr` instead of `stdout`
to circumvent buffering issues that exist by default on `stdout`.
See https://github.com/Pylons/pyramid/pull/3593

Deprecations
------------

Expand Down
14 changes: 10 additions & 4 deletions src/pyramid/scripts/pserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __init__(self, argv, quiet=False, original_ignore_files=None):

def out(self, msg): # pragma: no cover
if self.args.verbose > 0:
print(msg)
print(msg, file=sys.stderr)

def get_config_path(self, loader):
return os.path.abspath(loader.uri.path)
Expand Down Expand Up @@ -296,7 +296,9 @@ def wsgiref_server_runner(wsgi_app, global_conf, **kw): # pragma: no cover
host = kw.get('host', '0.0.0.0')
port = int(kw.get('port', 8080))
server = make_server(host, port, wsgi_app)
print('Starting HTTP server on http://%s:%s' % (host, port))
print(
'Starting HTTP server on http://%s:%s' % (host, port), file=sys.stderr
)
server.serve_forever()


Expand Down Expand Up @@ -416,10 +418,14 @@ def cherrypy_server_runner(
if host == '0.0.0.0':
print(
'serving on 0.0.0.0:%s view at %s://127.0.0.1:%s'
% (port, protocol, port)
% (port, protocol, port),
file=sys.stderr,
)
else:
print('serving on %s://%s:%s' % (protocol, host, port))
print(
'serving on %s://%s:%s' % (protocol, host, port),
file=sys.stderr,
)
server.start()
except (KeyboardInterrupt, SystemExit):
server.stop()
Expand Down

0 comments on commit 0ea2378

Please sign in to comment.