IMP logo
IMP Reference Guide  2.22.0
The Integrative Modeling Platform
manager_communicator.py
1 """@namespace IMP.parallel.manager_communicator
2  Classes for communicating from the manager to workers."""
3 
4 import socket
5 from IMP.parallel import _Communicator
6 
7 
8 class ManagerCommunicator(_Communicator):
9 
10  """For communicating from the manager to workers."""
11 
12  connect_timeout = 600
13 
14  def __init__(self, manager_addr, lock):
15  _Communicator.__init__(self)
16  self._manager_addr = manager_addr
17  self._connect_to_manager()
18  self._lock = lock
19 
20  def _connect_to_manager(self):
21  host, port, identifier = self._manager_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.encode('ascii'))
26  s.settimeout(None)
27  self._socket = s
28 
29  def _send(self, obj):
30  # Since the worker 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 manager to workers.
Distribute IMP tasks to multiple processors or machines.