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

Method emit

src/socketio/simple_client.py:108–131  ·  view source on GitHub ↗

Emit an event to the server. :param event: The event name. It can be any string. The event names ``'connect'``, ``'message'`` and ``'disconnect'`` are reserved and should not be used. :param data: The data to send to the server. Data can b

(self, event, data=None)

Source from the content-addressed store, hash-verified

106 return self.client.transport() if self.client else ''
107
108 def emit(self, event, data=None):
109 """Emit an event to the server.
110
111 :param event: The event name. It can be any string. The event names
112 ``'connect'``, ``'message'`` and ``'disconnect'`` are
113 reserved and should not be used.
114 :param data: The data to send to the server. Data can be of
115 type ``str``, ``bytes``, ``list`` or ``dict``. To send
116 multiple arguments, use a tuple where each element is of
117 one of the types indicated above.
118
119 This method schedules the event to be sent out and returns, without
120 actually waiting for its delivery. In cases where the client needs to
121 ensure that the event was received, :func:`socketio.SimpleClient.call`
122 should be used instead.
123 """
124 while True:
125 self.connected_event.wait()
126 if not self.connected:
127 raise DisconnectedError()
128 try:
129 return self.client.emit(event, data, namespace=self.namespace)
130 except SocketIOError:
131 pass
132
133 def call(self, event, data=None, timeout=60):
134 """Emit an event to the server and wait for a response.

Callers 3

test_emitMethod · 0.95
test_emit_retriesMethod · 0.95

Calls 2

DisconnectedErrorClass · 0.90
waitMethod · 0.45

Tested by 3

test_emitMethod · 0.76
test_emit_retriesMethod · 0.76