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?

1 Like

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?

Have the same problem .
I use Ne4j 4.1 with Python.
Have to upload nodes from complex text file . can't create the a CSV since the file will be too complex.
I set in Python the timeout to 200S but any way the upload is stopped after 100 new nodes , and then the session wait idle status till it terminated.

I have the same problem. I'm trying set up a timeout mechanism. I'm using neo4j 3.5 and HTTP API.

I make HTTP requests and get results. When a timeout happens I get empty response. But I can get empty response for a query anyway. So how can I know that if I get a timeout just by looking at HTTP response of neo4j?

I also asked this on here