IMP  2.0.1
The Integrative Modeling Platform
master_communicator.py
1 import socket
2 from IMP.parallel import _Communicator
3 
4 class MasterCommunicator(_Communicator):
5  connect_timeout = 600
6 
7  def __init__(self, master_addr, lock):
8  _Communicator.__init__(self)
9  self._master_addr = master_addr
10  self._connect_to_master()
11  self._lock = lock
12 
13  def _connect_to_master(self):
14  host, port, identifier = self._master_addr
15  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
16  s.settimeout(self.connect_timeout)
17  s.connect((host, port))
18  s.sendall(identifier)
19  s.settimeout(None)
20  self._socket = s
21 
22  def _send(self, obj):
23  # Since the slave is multi-threaded, must lock all access
24  self._lock.acquire()
25  try:
26  _Communicator._send(self, obj)
27  finally:
28  self._lock.release()