Letting a watch timeout

Hi folks!

The following Python script doesn’t trigger the transaction timeout on a pending watch operation. Am I doing something wrong?

import fdb
fdb.api_version(710)
db = fdb.open()
db.set(fdb.tuple.pack((1,)), fdb.tuple.pack((2,)))
tr = db.create_transaction()
tr.options.set_timeout(1000)
tr.watch(fdb.tuple.pack((1,))).wait()

I would expect the transaction to timeout after one second. What am I doing wrong?

OK, guess I got the txn API completely wrong. The following should make more sense, but I still don’t get a timeout:

import fdb
fdb.api_version(710)
db = fdb.open()
db.set(fdb.tuple.pack((1,)), fdb.tuple.pack((2,)))
tr = db.create_transaction()
tr.options.set_retry_limit(1)
tr.options.set_timeout(1000)
w = tr.watch(fdb.tuple.pack((1,)))
tr.commit()
w.wait()

Any suggestion? Thanks a lot!

Wooly thinking. So the lifetime of the watch is of course independent from the txn that created it and there doesn’t seem to be a way to let a watch timeout. So instead I tried a dump version of blocking synchronously on a watch by checking with watch.is_ready() and sleeping for some short amount of time if not. But now I’m not receiving any watch notifications and the test program just times out:

import fdb
import time

fdb.api_version(710)
db = fdb.open()
db.set(fdb.tuple.pack(("key",)), fdb.tuple.pack((time.time(),)))
tr = db.create_transaction()
w = tr.watch(fdb.tuple.pack(("key",)))
tr.commit()

start = time.time()
while True:
    if w.is_ready():
        print("value: %s" % w)
        break
    now = time.time()
    if (now - 10 > start):
        print("timeout\n")
        break
    time.sleep(1)

I’m running this twice: after starting a first instance I start a second one 1 or 2 seconds later. So the second instance should trigger the watch afaict.

What am I doing wrong this time? :slight_smile: Thanks!

Woohoo! Actually waiting for the txn to be committed fixes it, so tr.commit().wait() instead of just tr.commit()