Args: pipe_c2s, pipe_s2c (str): names of pipe to be used for communication
(self, pipe_c2s, pipe_s2c)
| 98 | self.ident = None |
| 99 | |
| 100 | def __init__(self, pipe_c2s, pipe_s2c): |
| 101 | """ |
| 102 | Args: |
| 103 | pipe_c2s, pipe_s2c (str): names of pipe to be used for communication |
| 104 | """ |
| 105 | super(SimulatorMaster, self).__init__() |
| 106 | assert os.name != 'nt', "Doesn't support windows!" |
| 107 | self.daemon = True |
| 108 | self.name = 'SimulatorMaster' |
| 109 | |
| 110 | self.context = zmq.Context() |
| 111 | |
| 112 | self.c2s_socket = self.context.socket(zmq.PULL) |
| 113 | self.c2s_socket.bind(pipe_c2s) |
| 114 | self.c2s_socket.set_hwm(10) |
| 115 | self.s2c_socket = self.context.socket(zmq.ROUTER) |
| 116 | self.s2c_socket.bind(pipe_s2c) |
| 117 | self.s2c_socket.set_hwm(10) |
| 118 | |
| 119 | # queueing messages to client |
| 120 | self.send_queue = queue.Queue(maxsize=100) |
| 121 | |
| 122 | def f(): |
| 123 | msg = self.send_queue.get() |
| 124 | self.s2c_socket.send_multipart(msg, copy=False) |
| 125 | self.send_thread = LoopThread(f) |
| 126 | self.send_thread.daemon = True |
| 127 | self.send_thread.start() |
| 128 | |
| 129 | # make sure socket get closed at the end |
| 130 | def clean_context(soks, context): |
| 131 | for s in soks: |
| 132 | s.close() |
| 133 | context.term() |
| 134 | import atexit |
| 135 | atexit.register(clean_context, [self.c2s_socket, self.s2c_socket], self.context) |
| 136 | |
| 137 | def run(self): |
| 138 | self.clients = defaultdict(self.ClientState) |
no test coverage detected