gunicorn icon indicating copy to clipboard operation
gunicorn copied to clipboard

RuntimeError: reentrant call inside <_io.BufferedWriter name='<stderr>'> (# 2667)

Open InfernalAzazel opened this issue 2 years ago • 2 comments

#2667 abnormal problems recur

gunicorn : 20.01

error:

2022-06-20 08:06:06 +0800] [7] [WARNING] Worker with pid 2855 was terminated due to signal 6
[2022-06-20 08:06:06 +0800] [2864] [INFO] Booting worker with pid: 2864
[2022-06-20 08:06:06 +0800] [7] [WARNING] Worker with pid 2856 was terminated due to signal 6
[2022-06-20 08:06:06 +0800] [7] [WARNING] Worker with pid 2861 was terminated due to signal 6
--- Logging error ---
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1103, in emit
    stream.write(msg + self.terminator)
RuntimeError: reentrant call inside <_io.BufferedWriter name='<stderr>'>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1103, in emit
    stream.write(msg + self.terminator)
  File "/usr/local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
    self.reap_workers()
  File "/usr/local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 530, in reap_workers
    self.log.warning(
  File "/usr/local/lib/python3.10/site-packages/gunicorn/glogging.py", line 261, in warning
    self.error_log.warning(msg, *args, **kwargs)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1489, in warning
    self._log(WARNING, msg, args, **kwargs)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1624, in _log
    self.handle(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1634, in handle
    self.callHandlers(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1696, in callHandlers
    hdlr.handle(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 968, in handle
    self.emit(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1108, in emit
    self.handleError(record)
  File "/usr/local/lib/python3.10/logging/__init__.py", line 1021, in handleError
    sys.stderr.write('--- Logging error ---\n')
RuntimeError: reentrant call inside <_io.BufferedWriter name='<stderr>'>
Call stack:
  File "/usr/local/bin/gunicorn", line 8, in <module>
    sys.exit(run())
  File "/usr/local/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 67, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/usr/local/lib/python3.10/site-packages/gunicorn/app/base.py", line 231, in run
    super().run()
  File "/usr/local/lib/python3.10/site-packages/gunicorn/app/base.py", line 72, in run
    Arbiter(self).run()
  File "/usr/local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 211, in run
    self.manage_workers()
  File "/usr/local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 551, in manage_workers
    self.spawn_workers()
  File "/usr/local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 623, in spawn_workers
    time.sleep(0.1 * random.random())
  File "/usr/local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
    self.reap_workers()
  File "/usr/local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 530, in reap_workers
    self.log.warning(
  File "/usr/local/lib/python3.10/site-packages/gunicorn/glogging.py", line 261, in warning
    self.error_log.warning(msg, *args, **kwargs)
Message: 'Worker with pid %s was terminated due to signal %s'
Arguments: (2861, 6)

code

import logging
import multiprocessing

from apscheduler.schedulers.background import BackgroundScheduler

from app.settings import TASK_TIME
from app.task import Task

bind = '0.0.0.0:80'
worker_class = 'uvicorn.workers.UvicornWorker'
workers = multiprocessing.cpu_count() * 2 + 1


def on_starting(_):
    logging.basicConfig()
    logging.getLogger('apscheduler').setLevel(logging.DEBUG)
    # 设置APScheduler注册的timezone
    scheduler = BackgroundScheduler()
    scheduler.add_job(Task.background_job, 'cron', hour=TASK_TIME['hour'], minute=TASK_TIME['minute'],
                      second=TASK_TIME['second'])
    scheduler.start()

cmd

gunicorn app.app:app -c gunicorn.conf.py

InfernalAzazel avatar Jun 20 '22 02:06 InfernalAzazel

after 2 years , this issue hasnt been fixed and now im getting thesame error

bengabp avatar Mar 05 '24 19:03 bengabp

The same here. :(

DmitriyLyalyuev avatar Apr 24 '24 15:04 DmitriyLyalyuev