IMP  2.3.0
The Integrative Modeling Platform
master_communicator.py
1 """@namespace IMP.parallel.master_communicator
2  Classes for communicating from the master to slaves."""
3 
4 import socket
5 from IMP.parallel import _Communicator
6 
7 
8 class MasterCommunicator(_Communicator):
9 
10  """For communicating from the master to slaves."""
11 
12  connect_timeout = 600
13 
14  def __init__(self, master_addr, lock):
15  _Communicator.__init__(self)
16  self._master_addr = master_addr
17  self._connect_to_master()
18  self._lock = lock
19 
20  def _connect_to_master(self):
21  host, port, identifier = self._master_addr
22  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
23  s.settimeout(self.connect_timeout)
24  s.connect((host, port))
25  s.sendall(identifier)
26  s.settimeout(None)
27  self._socket = s
28 
29  def _send(self, obj):
30  # Since the slave is multi-threaded, must lock all access
31  self._lock.acquire()
32  try:
33  _Communicator._send(self, obj)
34  finally:
35  self._lock.release()
For communicating from the master to slaves.
Distribute IMP tasks to multiple processors or machines.