MCPcopy
hub / github.com/django/django / asend_robust

Method asend_robust

django/dispatch/dispatcher.py:393–461  ·  view source on GitHub ↗

Send signal from sender to all connected receivers catching errors. If any receivers are synchronous, they are grouped and called behind a sync_to_async() adaption before executing any asynchronous receivers. If any receivers are asynchronous, they are grouped and

(self, sender, **named)

Source from the content-addressed store, hash-verified

391 return responses
392
393 async def asend_robust(self, sender, **named):
394 """
395 Send signal from sender to all connected receivers catching errors.
396
397 If any receivers are synchronous, they are grouped and called behind a
398 sync_to_async() adaption before executing any asynchronous receivers.
399
400 If any receivers are asynchronous, they are grouped and executed
401 concurrently with asyncio.TaskGroup.
402
403 Arguments:
404
405 sender
406 The sender of the signal. Can be any Python object (normally
407 one registered with a connect if you actually want something to
408 occur).
409
410 named
411 Named arguments which will be passed to receivers.
412
413 Return a list of tuple pairs [(receiver, response), ... ].
414
415 If any receiver raises an error (specifically any subclass of
416 Exception), return the error instance as the result for that receiver.
417 """
418 if (
419 not self.receivers
420 or self.sender_receivers_cache.get(sender) is NO_RECEIVERS
421 ):
422 return []
423
424 # Call each receiver with whatever arguments it can accept.
425 # Return a list of tuple pairs [(receiver, response), ... ].
426 sync_receivers, async_receivers = self._live_receivers(sender)
427
428 if sync_receivers:
429
430 @sync_to_async
431 def sync_send():
432 responses = []
433 for receiver in sync_receivers:
434 try:
435 response = receiver(signal=self, sender=sender, **named)
436 except Exception as err:
437 self._log_robust_failure(receiver, err)
438 responses.append((receiver, err))
439 else:
440 responses.append((receiver, response))
441 return responses
442
443 else:
444
445 async def sync_send():
446 return []
447
448 async def asend_and_wrap_exception(receiver):
449 try:
450 response = await receiver(signal=self, sender=sender, **named)

Calls 4

_live_receiversMethod · 0.95
_run_parallelFunction · 0.85
extendMethod · 0.80
getMethod · 0.45