reinis
reinis

Reputation: 1

import oracledb creates a new thread that does not work well with cherrypy

python 3.11 statement import oracledb

creates new thread

This confuses cherrypy, it fails to shut down gracefully and shows warning when daemonizing

import threading
print (threading.active_count())
import oracledb
print (threading.active_count())

import cherrypy
class Root(object):
    @cherrypy.expose
    def index(self):
        return "Hello World!"

cherrypy.quickstart(Root(), '/')

output, with attempt to shutdown (ctrl +c) :

1
2
[24/Jul/2024:16:57:36] ENGINE Listening for SIGTERM.
[24/Jul/2024:16:57:36] ENGINE Bus STARTING
CherryPy Checker:
The Application mounted at '' has an empty config.

[24/Jul/2024:16:57:36] ENGINE Started monitor thread 'Autoreloader'.
[24/Jul/2024:16:57:36] ENGINE Serving on http://127.0.0.1:8080
[24/Jul/2024:16:57:36] ENGINE Bus STARTED
[24/Jul/2024:16:57:41] ENGINE Keyboard Interrupt: shutting down bus
[24/Jul/2024:16:57:41] ENGINE Bus STOPPING
[24/Jul/2024:16:57:41] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('127.0.0.1', 8080)) shut down
[24/Jul/2024:16:57:41] ENGINE Stopped thread 'Autoreloader'.
[24/Jul/2024:16:57:41] ENGINE Bus STOPPED
[24/Jul/2024:16:57:41] ENGINE Bus EXITING
[24/Jul/2024:16:57:41] ENGINE Bus EXITED
[24/Jul/2024:16:57:41] ENGINE Waiting for child threads to terminate...
[24/Jul/2024:16:57:41] ENGINE Waiting for thread Thread-1 (close_pools_gracefully).

Also when trying to run cherrypy as daemon:

from cherrypy.process.plugins import Daemonizer
d = Daemonizer(cherrypy.engine)
d.subscribe()
cherrypy.quickstart(Root(), '/')

output:

1
2
[24/Jul/2024:17:08:36] ENGINE Listening for SIGTERM.
[24/Jul/2024:17:08:36] ENGINE Listening for SIGHUP.
[24/Jul/2024:17:08:36] ENGINE Listening for SIGUSR1.
[24/Jul/2024:17:08:36] ENGINE Bus STARTING
CherryPy Checker:
The Application mounted at '' has an empty config.

[24/Jul/2024:17:08:36] ENGINE There are [<_MainThread(MainThread, started 139910406747776)>, <Thread(Thread-1 (close_pools_gracefully), started 139910279526144)>] active threads. Daemonizing now may cause strange failures.
[24/Jul/2024:17:08:36] ENGINE Forking once.
<enter> [24/Jul/2024:17:08:36] ENGINE Forking twice.

Upvotes: 0

Views: 41

Answers (0)

Related Questions