eclipse-cyclonedds / cyclonedds-python

Other
64 stars 47 forks source link

Waitset on DDSStatus #267

Closed jc211 closed 1 month ago

jc211 commented 1 month ago

Can a waitset be used to wait for a subscribtion_matched event?

jc211 commented 1 month ago

Here is how I got it to work:

waitset = Waitset(participant)
waitset.attach(data_reader)
data_reader.set_status_mask(DDSStatus.SubscriptionMatched)
waitset.wait()
jc211 commented 1 month ago

Also using a listener at the same time with a WaitSet will not work. Make sure no listeners are attached.

eboasson commented 1 month ago

@jc211

Also using a listener at the same time with a WaitSet will not work. Make sure no listeners are attached.

Correct, at least in practice. In theory it is slightly more complicated, and I figured you might find knowing the background useful.

The behaviour you see is because the spec (1) considers the invocation of the listener the same as reading the status and resetting the flag [^1], and (2) requires that the listeners be called before waitsets are triggered. The result is that the status conditions can't be meaningfully combined ...

With multiple conditions in the waitset, there are usually some interleavings where you can return from the waitset before the listener is called for some unrelated reason and so it is best to just avoid combining them.

In short the "avoid this, it doesn't work" is good advice! 🙂

[^1]: I don't quite agree with their reasoning and so the C API has an extension to invoke listeners without affecting the state, but that is of little use to you here.