def channel_session(func):
 @functools.wraps(func)
 def inner(message, *args, **kwargs):
  if hasattr(message, 'channel_session'):
   try:
    return func(message, *args, **kwargs)
   finally:
    if message.channel_session.modified:
     message.channel_session.save()
  if (not message.reply_channel):
   raise ValueError(('No reply_channel sent to consumer; @channel_session ' + 'can only be used on messages containing it.'))
  session = session_for_reply_channel(message.reply_channel.name)
  if (not session.exists(session.session_key)):
   try:
    session.save(must_create=True)
   except CreateError:
    raise ConsumeLater()
  message.channel_session = session
  try:
   return func(message, *args, **kwargs)
  finally:
   if (session.modified and (not session.is_empty())):
    session.save()
 return inner

def channel_session ( func ) : @ functools . wraps ( func ) def inner ( message , * args , ** kwargs ) : if hasattr ( message , 'channel_session' ) : try : return func ( message , * args , ** kwargs ) finally : if message . channel_session . modified : message . channel_session . save ( ) if ( not message . reply_channel ) : raise ValueError ( ( 'No reply_channel sent to consumer; @channel_session ' + 'can only be used on messages containing it.' ) ) session = session_for_reply_channel ( message . reply_channel . name ) if ( not session . exists ( session . session_key ) ) : try : session . save ( must_create = True ) except CreateError : raise ConsumeLater ( ) message . channel_session = session try : return func ( message , * args , ** kwargs ) finally : if ( session . modified and ( not session . is_empty ( ) ) ) : session . save ( ) return inner
provides a session-like object called "channel_session" to consumers as a message attribute that will auto-persist across consumers with the same incoming "reply_channel" value .