Python driver - specify timeout in session/transaction

I am using neo4j python driver 1.7.4 to issue queries to the db. Some of the queries take longer than the others. So, I am trying to specify a timeout parameter when running sessions/transactions. (I am aware of the global setting in neo4j.conf dbms.transaction.timeout=120s but I want to set the timeout at the transaction level, not at the database level)

Here is my python code but this doesn't seem to work. The below query executes for more than 50 sec and doesn't terminate.

    with self._driver.session() as session:
            result ="match(p:Person)--(n) return p,count(n)",{"timeout": "50s"})

        except Exception as ex:
            print("Exception occurred:" + ex)

Can anyone provide me the correct way to specify timeouts?

Hi there,

The timeout is not an option for The 2nd argument in the function is parameters to be passed to the query. ie, if you had MATCH (p:Person) WHERE{name}, then you could pass a dictionary in as the second argument saying {"name": "Kate"} and it would use that value for the query.

Perhaps look at this example for a decorator that you can apply in a "transaction function":

neo4j. unit_of_work ( metadata=None , timeout=None )

This function is a decorator for transaction functions that allows extra control over how the transaction is carried out.

For example, a timeout (in seconds) may be applied:

def count_people(tx):
  return"MATCH (a:Person) RETURN count(a)").single().value()


I have gone through this documentation but the timeout isn't working. Is there any additional config setting (ex. neo4j.conf) to get this working?