IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
manager_communicator.py
1"""@namespace IMP.parallel.manager_communicator
2 Classes for communicating from the manager to workers."""
3
4import socket
5from IMP.parallel import _Communicator
6
7
8class 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 super().__init__()
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.