def setup_transaction_hook(config):
 def _notify_resource_events_before(request):
  'Notify the accumulated resource events before end of transaction.\n        '
  for event in request.get_resource_events():
   request.registry.notify(event)
 def _notify_resource_events_after(success, request):
  'Notify the accumulated resource events if transaction succeeds.\n        '
  if success:
   for event in request.get_resource_events(after_commit=True):
    try:
     request.registry.notify(event)
    except Exception:
     logger.error('Unable to notify', exc_info=True)
 def on_new_request(event):
  'When a new request comes in, hook on transaction commit.\n        '
  if hasattr(event.request, 'parent'):
   return
  current = transaction.get()
  current.addBeforeCommitHook(_notify_resource_events_before, args=(event.request,))
  current.addAfterCommitHook(_notify_resource_events_after, args=(event.request,))
 config.add_subscriber(on_new_request, NewRequest)

def setup_transaction_hook ( config ) : def _notify_resource_events_before ( request ) : for event in request . get_resource_events ( ) : request . registry . notify ( event ) def _notify_resource_events_after ( success , request ) : if success : for event in request . get_resource_events ( after_commit = True ) : try : request . registry . notify ( event ) except Exception : logger . error ( 'Unable to notify' , exc_info = True ) def on_new_request ( event ) : if hasattr ( event . request , 'parent' ) : return current = transaction . get ( ) current . addBeforeCommitHook ( _notify_resource_events_before , args = ( event . request , ) ) current . addAfterCommitHook ( _notify_resource_events_after , args = ( event . request , ) ) config . add_subscriber ( on_new_request , NewRequest )
resource events are plugged with the transactions of pyramid_tm .