diff --git a/gunicorn/app/base.py b/gunicorn/app/base.py index bc6ea188..4295230d 100644 --- a/gunicorn/app/base.py +++ b/gunicorn/app/base.py @@ -2,6 +2,7 @@ # # This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. +from __future__ import print_function import os import sys @@ -34,7 +35,7 @@ class BaseApplication(object): self.load_default_config() self.load_config() except Exception as e: - sys.stderr.write("\nError: %s\n" % str(e)) + print("\nError: %s" % str(e), file=sys.stderr) sys.stderr.flush() sys.exit(1) @@ -70,7 +71,7 @@ class BaseApplication(object): try: Arbiter(self).run() except RuntimeError as e: - sys.stderr.write("\nError: %s\n\n" % e) + print("\nError: %s\n" % e, file=sys.stderr) sys.stderr.flush() sys.exit(1) @@ -91,8 +92,9 @@ class Application(BaseApplication): try: execfile_(filename, cfg, cfg) except Exception: - print("Failed to read config file: %s" % filename) + print("Failed to read config file: %s" % filename, file=sys.stderr) traceback.print_exc() + sys.stderr.flush() sys.exit(1) return cfg @@ -118,7 +120,8 @@ class Application(BaseApplication): try: self.cfg.set(k.lower(), v) except: - sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v)) + print("Invalid value for %s: %s\n" % (k, v), file=sys.stderr) + sys.stderr.flush() raise return cfg @@ -162,7 +165,8 @@ class Application(BaseApplication): try: self.load() except: - sys.stderr.write("\nError while loading the application:\n\n") + msg = "\nError while loading the application:\n" + print(msg, file=sys.stderr) traceback.print_exc() sys.stderr.flush() sys.exit(1) diff --git a/gunicorn/app/django_wsgi.py b/gunicorn/app/django_wsgi.py index 1b1374e2..31d8aec2 100644 --- a/gunicorn/app/django_wsgi.py +++ b/gunicorn/app/django_wsgi.py @@ -4,6 +4,7 @@ # See the NOTICE for more information. """ module used to build the django wsgi application """ +from __future__ import print_function import os import re @@ -36,9 +37,9 @@ def make_wsgi_application(): if get_validation_errors(s): s.seek(0) error = s.read() - sys.stderr.write("One or more models did not validate:\n%s" % error) + msg = "One or more models did not validate:\n%s" % error + print(msg, file=sys.stderr) sys.stderr.flush() - sys.exit(1) translation.activate(settings.LANGUAGE_CODE) diff --git a/gunicorn/app/pasterapp.py b/gunicorn/app/pasterapp.py index d24ea780..ee40fd8f 100644 --- a/gunicorn/app/pasterapp.py +++ b/gunicorn/app/pasterapp.py @@ -2,6 +2,7 @@ # # This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. +from __future__ import print_function import os import pkg_resources @@ -155,7 +156,7 @@ class PasterServerApplication(PasterBaseApplication): if k.lower() in self.cfg.settings and v is not None: self.cfg.set(k.lower(), v) except Exception as e: - sys.stderr.write("\nConfig error: %s\n" % str(e)) + print("\nConfig error: %s" % str(e), file=sys.stderr) sys.stderr.flush() sys.exit(1) diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index aa89b753..d92444e1 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -2,6 +2,7 @@ # # This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. +from __future__ import print_function import errno import os @@ -520,8 +521,7 @@ class Arbiter(object): except AppImportError as e: self.log.debug("Exception while loading the application: \n%s", traceback.format_exc()) - - sys.stderr.write("%s\n" % e) + print("%s" % e, file=sys.stderr) sys.stderr.flush() sys.exit(self.APP_LOAD_ERROR) except: diff --git a/gunicorn/util.py b/gunicorn/util.py index 2df3f574..42f8b8a4 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -3,6 +3,7 @@ # This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. +from __future__ import print_function import email.utils import fcntl @@ -520,13 +521,13 @@ def is_fileobject(obj): def warn(msg): - sys.stderr.write("!!!\n") + print("!!!", file=sys.stderr) lines = msg.splitlines() for i, line in enumerate(lines): if i == 0: line = "WARNING: %s" % line - sys.stderr.write("!!! %s\n" % line) + print("!!! %s" % line, file=sys.stderr) - sys.stderr.write("!!!\n\n") + print("!!!\n", file=sys.stderr) sys.stderr.flush()