Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
InfernalAzazel opened this issue Jun 20, 2022 · 4 comments · May be fixed by #3064
Open

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

InfernalAzazel opened this issue Jun 20, 2022 · 4 comments · May be fixed by #3064

Comments

@InfernalAzazel
Copy link

InfernalAzazel commented Jun 20, 2022

#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 InfernalAzazel changed the title RuntimeError: reentrant call inside <_io.BufferedWriter name='<stderr>'> #2667 RuntimeError: reentrant call inside <_io.BufferedWriter name='<stderr>'> # 2667 Jun 20, 2022
@InfernalAzazel InfernalAzazel changed the title RuntimeError: reentrant call inside <_io.BufferedWriter name='<stderr>'> # 2667 RuntimeError: reentrant call inside <_io.BufferedWriter name='<stderr>'> (# 2667) Sep 1, 2022
changsu-bWell added a commit to icanbwell/helix-service-template that referenced this issue Apr 13, 2023
gunicorn = "==20.0.4" # 20.1.0 has this issue benoitc/gunicorn#2816
hydrargyrum added a commit to hydrargyrum/gunicorn that referenced this issue Sep 5, 2023
Fixes benoitc#2816

Logging stuff in a signal handler cannot work and thus must not be done.
https://docs.python.org/3/library/logging.html#thread-safety
hydrargyrum added a commit to hydrargyrum/gunicorn that referenced this issue Sep 5, 2023
@hydrargyrum hydrargyrum linked a pull request Sep 5, 2023 that will close this issue
@bengabp
Copy link

bengabp commented Mar 5, 2024

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

@DmitriyLyalyuev
Copy link

The same here. :(

@randomir
Copy link

Regression of #2564.

@ChanChiChoi
Copy link

the same here,too

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 a pull request may close this issue.

5 participants