Hi, in one of my Odoo15 installation I need to setup the socket_timeout variable of WorkerHTTP class directly from Python code, bypassing the usage of environment variable ODOO_HTTP_SOCKET_TIMEOUT.
EDIT: a guy on stackoverflow introduced me on monkey patching oop tecnique, which i didn't know before. As I thaught it's actually pretty easy, but you must know how it works. For now it's far from being perfect, but it works, I will update post if I will improve it (it's just a temporary workaround for one of my installations).
import errno
import fcntl
import socket
import odoo
import odoo.service.server as srv
class WorkerHttpProcessRequestPatch(srv.WorkerHTTP):
def process_request(self, client, addr):
client.setblocking(1)
client.settimeout(100) # v0.1, i will make it much better but i want a backup
client.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
flags = fcntl.fcntl(client, fcntl.F_GETFD) | fcntl.FD_CLOEXEC
fcntl.fcntl(client, fcntl.F_SETFD, flags)
self.server.socket = client
try:
self.server.process_request(client, addr)
except IOError as e:
if e.errno != errno.EPIPE:
raise
self.request_count += 1
odoo.service.server.WorkerHTTP.process_request = WorkerHttpProcessRequestPatch.process_request
The last line is just magic, if I understand well it switch attribute process_request of WorkerHTTP with custom process_request attribute at runtime, so the object is initialized with old class name, but process_request is executed with my custom method.
It must be set statically from code for now, so it's ugly, but at least it does bypass ODOO_HTTP_SOCKET_TIMEOUT environment variable as I needed and at the same time it does not get override from updates.
I'd like to make a module for that to be able to setup from UI if some one is interested.