Kill Queries Example Script

  • 19 July 2021
  • 2 replies

Userlevel 4
  • Looker Staff
  • 30 replies

Hi all, 

Running an excessive amount queries simultaneously may lead to degraded Looker instance performance, especially queries run by an API user to send out bulk schedules or queries requiring post-processing features (such as merged results, custom fields, and table calculations). In these situations, the fastest way to bring an instance back to a normal stage is to kill all running queries to help with restoring CPU and memory.  

I am sharing an example script to kill running queries using Looker Python SDK (either all running queries, or selective queries with two optional arguments: 'user_id' and 'source')

Link to Google Colab to run as an one-off task. 

import looker_sdk
sdk = looker_sdk.init40()

def kill_queries(user_id=None, source=None):

  """Kill running queries in an instance.
  user_id(int): id of the user whose queries are to be killed 
  source(str): common values are 'merge_query', 'explore', 'dashboard', 'look', 'regenerator'  

  queries = sdk.all_running_queries()

  if len(queries) == 0:
    print('Currently, there is no running query in the instance')
    for i in range(0, len(queries)):   
        if queries[i]['source'] == source or queries[i]['user']['id'] == user_id: 
          print('Killed query task id' + queries[i]['query_task_id'])

          print('Currently, there are no running queries that meet the conditions')

kill_queries(user_id=1, source='merge_query')


2 replies

hi Lan, I have been trying to download dashboards in pdf format but no luck using looker_sdk.. by any chance do you have anything handy ?


Userlevel 4

Hi Naren, have you tried testing with this example script from Looker Python SDK example repo?