IMP  2.1.1
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 class MasterCommunicator(_Communicator):
8  """For communicating from the master to slaves."""
9 
10  connect_timeout = 600
11 
12  def __init__(self, master_addr, lock):
13  _Communicator.__init__(self)
14  self._master_addr = master_addr
15  self._connect_to_master()
16  self._lock = lock
17 
18  def _connect_to_master(self):
19  host, port, identifier = self._master_addr
20  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
21  s.settimeout(self.connect_timeout)
22  s.connect((host, port))
23  s.sendall(identifier)
24  s.settimeout(None)
25  self._socket = s
26 
27  def _send(self, obj):
28  # Since the slave is multi-threaded, must lock all access
29  self._lock.acquire()
30  try:
31  _Communicator._send(self, obj)
32  finally:
33  self._lock.release()
For communicating from the master to slaves.
See IMP.parallel for more information.