mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 01:52:55 +00:00 
			
		
		
		
	Initialise supervisor xmlrpc client lazily to avoid globals
This commit is contained in:
		@@ -29,7 +29,6 @@ class LogMonitor(ObserverMixin):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class SendLogWatchdogEventHandler(PatternMatchingWatchdogEventHandler, SupervisorLogMixin):
 | 
					class SendLogWatchdogEventHandler(PatternMatchingWatchdogEventHandler, SupervisorLogMixin):
 | 
				
			||||||
    def __init__(self, process_name, log_tail=0):
 | 
					    def __init__(self, process_name, log_tail=0):
 | 
				
			||||||
        self.acquire_own_supervisor_instance()  # This thread-localises the xmlrpc client
 | 
					 | 
				
			||||||
        self.process_name = process_name
 | 
					        self.process_name = process_name
 | 
				
			||||||
        self.procinfo = self.supervisor.getProcessInfo(self.process_name)
 | 
					        self.procinfo = self.supervisor.getProcessInfo(self.process_name)
 | 
				
			||||||
        super().__init__([self.procinfo['stdout_logfile'], self.procinfo['stderr_logfile']])
 | 
					        super().__init__([self.procinfo['stdout_logfile'], self.procinfo['stderr_logfile']])
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,21 +6,14 @@ from xmlrpc.client import Fault as SupervisorFault
 | 
				
			|||||||
from contextlib import suppress
 | 
					from contextlib import suppress
 | 
				
			||||||
from os import remove
 | 
					from os import remove
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from tfw.decorators import LazyInitialise
 | 
				
			||||||
from tfw.config import TFWENV
 | 
					from tfw.config import TFWENV
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_supervisor_instance():
 | 
					 | 
				
			||||||
    return xmlrpc.client.ServerProxy(TFWENV.SUPERVISOR_HTTP_URI).supervisor
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class SupervisorBaseMixin:
 | 
					class SupervisorBaseMixin:
 | 
				
			||||||
    supervisor = get_supervisor_instance()
 | 
					    @LazyInitialise
 | 
				
			||||||
 | 
					    def supervisor(self):
 | 
				
			||||||
    def acquire_own_supervisor_instance(self):
 | 
					        return xmlrpc.client.ServerProxy(TFWENV.SUPERVISOR_HTTP_URI).supervisor
 | 
				
			||||||
        """
 | 
					 | 
				
			||||||
        Give this instance non-static, local xmlrpc client
 | 
					 | 
				
			||||||
        """
 | 
					 | 
				
			||||||
        self.supervisor = get_supervisor_instance()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SupervisorMixin(SupervisorBaseMixin):
 | 
					class SupervisorMixin(SupervisorBaseMixin):
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user