MCPcopy Create free account
hub / github.com/miguelgrinberg/python-socketio / call

Method call

src/socketio/simple_client.py:133–161  ·  view source on GitHub ↗

Emit an event to the server and wait for a response. This method issues an emit and waits for the server to provide a response or acknowledgement. If the response does not arrive before the timeout, then a ``TimeoutError`` exception is raised. :param event: The even

(self, event, data=None, timeout=60)

Source from the content-addressed store, hash-verified

131 pass
132
133 def call(self, event, data=None, timeout=60):
134 """Emit an event to the server and wait for a response.
135
136 This method issues an emit and waits for the server to provide a
137 response or acknowledgement. If the response does not arrive before the
138 timeout, then a ``TimeoutError`` exception is raised.
139
140 :param event: The event name. It can be any string. The event names
141 ``'connect'``, ``'message'`` and ``'disconnect'`` are
142 reserved and should not be used.
143 :param data: The data to send to the server. Data can be of
144 type ``str``, ``bytes``, ``list`` or ``dict``. To send
145 multiple arguments, use a tuple where each element is of
146 one of the types indicated above.
147 :param timeout: The waiting timeout. If the timeout is reached before
148 the server acknowledges the event, then a
149 ``TimeoutError`` exception is raised.
150 """
151 while True:
152 self.connected_event.wait()
153 if not self.connected:
154 raise DisconnectedError()
155 try:
156 return self.client.call(event, data, namespace=self.namespace,
157 timeout=timeout)
158 except TimeoutError:
159 raise
160 except SocketIOError:
161 pass
162
163 def receive(self, timeout=None):
164 """Wait for an event from the server.

Callers 4

test_callMethod · 0.95
test_call_retriesMethod · 0.95
test_call_timeoutMethod · 0.95

Calls 2

DisconnectedErrorClass · 0.90
waitMethod · 0.45

Tested by 4

test_callMethod · 0.76
test_call_retriesMethod · 0.76
test_call_timeoutMethod · 0.76