In my application contain both server and client. I have implemented gunicorn in server. the server side contain 5 python files.I Implemented gunicorn in server.py.when server and client is connected , the details of clients available within function handle_client only, before applying gunicorn details of client can be accessed every where within Class.So I think there is a problem gunicorn with thread. please give me a proper solution. here I give you some code snippets
class StandaloneApplication(BaseApplication):
def __init__(self, app, options=None):
self.options = options or {}
self.application = app
super().__init__()
def load_config(self):
for key, value in self.options.items():
if key in self.cfg.settings and value is not None:
self.cfg.set(key.lower(), value)
def load(self):
return self.application
if name == "main": try:
# Start the TCP server
server.start_tcp_server()
# Start accepting connections in a separate thread
accept_thread = threading.Thread(target=server.get_connections)
accept_thread.start()
options = {
'bind': '%s:%s' % (server.server_host, server.web_port),
'workers': multiprocessing.cpu_count() * 2 + 1, # Number of worker processes
'threads': multiprocessing.cpu_count() * 2 ,
'debug': False,
'use_reloader': False,
# Add more Gunicorn config options as needed
}
# Create an instance of StandaloneApplication
gunicorn_app = StandaloneApplication(app, options)
# Run Gunicorn with the StandaloneApplication
gunicorn_app.run()
except KeyboardInterrupt:
event_logger.log_info("Server connection closed.")
finally:
# Close the server socket and perform any other cleanup
server.server_socket.close()
sys.exit(0)