Browse Source

Flush stderr before exiting with error code 1. (#4611)

Otherwise, in some environments (at least docker and kubernetes)
it is possible that celery exits with error 1 without displaying
the cause of the error.

Closes #4594.
Antonin Delpeuch 7 years ago
parent
commit
1a4497e947
3 changed files with 3 additions and 0 deletions
  1. 1 0
      celery/platforms.py
  2. 1 0
      celery/utils/threads.py
  3. 1 0
      celery/utils/timer2.py

+ 1 - 0
celery/platforms.py

@@ -791,6 +791,7 @@ def check_privileges(accept_content):
                         uid=uid, euid=euid, gid=gid, egid=egid,
                     ), file=sys.stderr)
                 finally:
+                    sys.stderr.flush()
                     os._exit(1)
         warnings.warn(RuntimeWarning(ROOT_DISCOURAGED.format(
             uid=uid, euid=euid, gid=gid, egid=egid,

+ 1 - 0
celery/utils/threads.py

@@ -74,6 +74,7 @@ class bgThread(threading.Thread):
                         self.on_crash('{0!r} crashed: {1!r}', self.name, exc)
                         self._set_stopped()
                     finally:
+                        sys.stderr.flush()
                         os._exit(1)  # exiting by normal means won't work
         finally:
             self._set_stopped()

+ 1 - 0
celery/utils/timer2.py

@@ -91,6 +91,7 @@ class Timer(threading.Thread):
                 pass
         except Exception as exc:
             logger.error('Thread Timer crashed: %r', exc, exc_info=True)
+            sys.stderr.flush()
             os._exit(1)
 
     def stop(self):