mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-09 01:47:16 +00:00
34 lines
859 B
Python
34 lines
859 B
Python
import xmlrpc.client, zmq
|
|
from contextlib import suppress
|
|
from xmlrpc.client import Fault as SupervisorFault
|
|
|
|
from tfw.config import tfwenv
|
|
|
|
|
|
def create_source_code_response_data(filename, content, language):
|
|
return {
|
|
'filename': filename,
|
|
'content': content,
|
|
'language': language
|
|
}
|
|
|
|
|
|
class SupervisorMixin:
|
|
supervisor = xmlrpc.client.ServerProxy(tfwenv.SUPERVISOR_HTTP_URI).supervisor
|
|
|
|
def stop_process(self):
|
|
with suppress(SupervisorFault):
|
|
self.supervisor.stopProcess(self.process_name)
|
|
|
|
def start_process(self):
|
|
self.supervisor.startProcess(self.process_name)
|
|
|
|
def restart_process(self):
|
|
self.stop_process()
|
|
self.start_process()
|
|
|
|
|
|
class ZMQConnectorBase:
|
|
def __init__(self, zmq_context=None):
|
|
self._zmq_context = zmq_context or zmq.Context.instance()
|