Sends a new request, and returns the OutgoingRequest object for it. If arguments is None or {}, "arguments" will be omitted in JSON. If on_before_send is not None, invokes on_before_send() with the request object as the sole argument, before the request actually gets sent.
(self, command, arguments=None, on_before_send=None)
| 1224 | self.stream.write_json(message) |
| 1225 | |
| 1226 | def send_request(self, command, arguments=None, on_before_send=None): |
| 1227 | """Sends a new request, and returns the OutgoingRequest object for it. |
| 1228 | |
| 1229 | If arguments is None or {}, "arguments" will be omitted in JSON. |
| 1230 | |
| 1231 | If on_before_send is not None, invokes on_before_send() with the request |
| 1232 | object as the sole argument, before the request actually gets sent. |
| 1233 | |
| 1234 | Does not wait for response - use OutgoingRequest.wait_for_response(). |
| 1235 | |
| 1236 | Safe to call concurrently for the same channel from different threads. |
| 1237 | """ |
| 1238 | |
| 1239 | d = {"type": "request", "command": command} |
| 1240 | if arguments is not None and arguments != {}: |
| 1241 | d["arguments"] = arguments |
| 1242 | |
| 1243 | with self._send_message(d) as seq: |
| 1244 | request = OutgoingRequest(self, seq, command, arguments) |
| 1245 | if on_before_send is not None: |
| 1246 | on_before_send(request) |
| 1247 | self._sent_requests[seq] = request |
| 1248 | return request |
| 1249 | |
| 1250 | def send_event(self, event, body=None): |
| 1251 | """Sends a new event. |