'LibreTranslate library in python gives 500 Internal server error after running for times

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



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source