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:
        try:
            result = session.run("match(p:Person)--(n) return p,count(n)",{"timeout": "50s"})
            print(result.single())

        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 session.run. The 2nd argument in the session.run() function is parameters to be passed to the query. ie, if you had MATCH (p:Person) WHERE p.name={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":
https://neo4j.com/docs/api/python-driver/current/transactions.html#transaction-functions

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:

@unit_of_work(timeout=25.0)
def count_people(tx):
  return tx.run("MATCH (a:Person) RETURN count(a)").single().value()

Cheers,
-Ryan

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?