Transaction error

When I tried to use py2neo to create 400000 nodes and 800000 relationships at once, this error occurred: [Transaction.TransactionNotFound] Unrecognized transaction id. Transaction may have timed out and been rolled back.
The original code is as follows:
tx = graph.begin()
tx.create(subgraph=Subgraph(nodes=all_nodes))
for i in range(0,int(len(all_create_relationships)/single_summit_value)+1):
start=i*single_summit_value
end=(i+1)*single_summit_value
if end>len(all_create_relationships):
end=len(all_create_relationships)
try:
subgraph=Subgraph(relationships=all_create_relationships[start:end])
tx.create(subgraph)

        except Exception as e:
            graph.rollback(tx)
            print(f"Transaction rolled back: {e}")

    graph.commit(tx)