0

I have setup libretranslate on my local system (ubuntu focal fossa) by following steps described by https://github.com/LibreTranslate/LibreTranslate url and scaled the app with gunicorn and nginx as described in the same tutorial. I have created libretranslate as ubuntu service unit. below is my ExecStart command of my service file.

ExecStart=/home/support/LibreTranslate/env/bin/gunicorn --workers 3 --log-level 'error' --error-logfile /home/support/LibreTranslate/Logs/gunicorn_nohup.log --bind unix:libretranslate.sock -m 007 wsgi:app

I started gunicorn with 3 worker. However, after running for sometimes, it started to give 500 internal server error. Below is log generated by gunicorn

[2022-05-10 13:44:03 +0100] [306482] [ERROR] Error handling request /detect
Traceback (most recent call last):
  File "/home/support/LibreTranslate/env/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 136, in handle
    self.handle_request(listener, req, client, addr)
  File "/home/support/LibreTranslate/env/lib/python3.8/site-packages/gunicorn/workers/sync.py", line 179, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/home/support/LibreTranslate/wsgi.py", line 14, in app
    instance = main()
  File "/home/support/LibreTranslate/app/main.py", line 121, in main
    app = create_app(args)
  File "/home/support/LibreTranslate/app/app.py", line 113, in create_app
    remove_translated_files.setup(get_upload_dir())
  File "/home/support/LibreTranslate/app/remove_translated_files.py", line 23, in setup
    scheduler.start()
  File "/home/support/LibreTranslate/env/lib/python3.8/site-packages/apscheduler/schedulers/background.py", line 38, in start
    self._thread.start()
  File "/usr/lib/python3.8/threading.py", line 852, in start
    _start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread

Does anyone knows why this is happening? And Is there any other way to achieve same without facing this issue?

I have raised issue on LibreTransate community. here is the link https://community.libretranslate.com/t/python-library-of-libretranslate-run-with-gunicorn-and-nginx-not-freeing-up-threads/221

and link to GH issue https://github.com/argosopentech/LibreTranslate-init/issues/10

pjsagar
  • 241
  • 3
  • 11
  • You most definitely starting more threads than what is allowed for your program. You can check how many threads one process is allowed to have, and check this answer for more information https://stackoverflow.com/a/65030992/5540592 – WiLL_K May 11 '22 at 11:03
  • The thing is that, app is running under gunicorn server and the threads are not getting freed after the request is served. This is causing thread count to max out so no more new threads get created. By the way, have updated the question with raised issue link – pjsagar May 13 '22 at 05:40
  • May be this link could help https://github.com/benoitc/gunicorn/issues/1045 – WiLL_K May 13 '22 at 08:04

0 Answers0