def Handle(environ):
 error = logservice.LogsBuffer()
 request_environment.current_request.Init(error, environ)
 response = {'error': 0, 'response_code': 200}
 try:
  request_id = environ[BACKGROUND_REQUEST_ID]
  _pending_background_threads.RunBackgroundThread(request_id)
  return response
 except:
  exception = sys.exc_info()
  tb = exception[2].tb_next
  if tb:
   tb = tb.tb_next
  message = ''.join(traceback.format_exception(exception[0], exception[1], tb))
  logging.error(message)
  response['response_code'] = 500
  response['error'] = 1
  return response
 finally:
  request_environment.current_request.Clear()
  response['logs'] = error.parse_logs()

def Handle ( environ ) : error = logservice . LogsBuffer ( ) request_environment . current_request . Init ( error , environ ) response = { 'error' : 0 , 'response_code' : 200 } try : request_id = environ [ BACKGROUND_REQUEST_ID ] _pending_background_threads . RunBackgroundThread ( request_id ) return response except : exception = sys . exc_info ( ) tb = exception [ 2 ] . tb_next if tb : tb = tb . tb_next message = '' . join ( traceback . format_exception ( exception [ 0 ] , exception [ 1 ] , tb ) ) logging . error ( message ) response [ 'response_code' ] = 500 response [ 'error' ] = 1 return response finally : request_environment . current_request . Clear ( ) response [ 'logs' ] = error . parse_logs ( )
handles a background request .