schrodinger.tasks.taskszmq module¶
Provides a Qt-based interface for a ZMQ REP server and REQ client. The server class is designed for use in an event-driven application and reports updates via Qt signals.
Example usage:
- class MyServer(ZmqServer):
- def makeReply(self, request):
- if request == ‘hello’:
return ‘world’
- elif request == ‘goodbye’:
return ‘cruel world’
server = MyServer() port_num = server.port_num
In a separate process/thread:
client = ZmqClient(‘localhost’, port_num) reply = client.request(‘hello’) assert reply == ‘world’
- exception schrodinger.tasks.taskszmq.TimeoutError¶
Bases:
RuntimeError
- class schrodinger.tasks.taskszmq.Context(io_threads: int = 1, **kwargs: Any)¶
Bases:
zmq.sugar.context.Context
- socket(*args, **kwargs)¶
Create a Socket associated with this Context.
- socket_typeint
The socket type, which can be any of the 0MQ socket types: REQ, REP, PUB, SUB, PAIR, DEALER, ROUTER, PULL, PUSH, etc.
- kwargs:
will be passed to the __init__ method of the socket class.
- class schrodinger.tasks.taskszmq.ZmqServer(port_num=None)¶
Bases:
PyQt6.QtCore.QObject
The ZmqServer class provides a Qt-based interface for a ZMQ REP server. To use, subclass and override the makeReply method to generate a reply for each request.
- requestReceived¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- replySent¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- __init__(port_num=None)¶
- makeReply(request)¶
- shutdown()¶
Shutdown the server. This method blocks until shutdown is complete.
- class schrodinger.tasks.taskszmq.ZmqClient(server_host, port_num)¶
Bases:
PyQt6.QtCore.QObject
The ZmqClient class provides a Qt-based interface for a ZMQ REQ client. To use, create an instance and call the request method to send a request and receive a reply from the server.
ZmqClient should not be used in the main GUI thread, and cannot be run in the same thread as the server, due to blocking zmq operations.
- __init__(server_host, port_num)¶
- request(string, timeout=10)¶
Send a request to the server and wait for a reply. If no reply is received within the timeout, a TimeoutError is raised.
- Parameters
string – the request string
timeout – time to wait for the server to reply (seconds)
- Returns
the reply string
- shutdown()¶
- schrodinger.tasks.taskszmq.get_portnum()¶