Confusion on using wait() vs. add_callback() #408
-
Hi everyone, I am still relatively new to bacpypes and am generally confused on knowing when to implement wait() vs add_callback() and also feel I may not be implementing them correctly? I have been building most of my applications with add_callback() and RecurringTask, everything was working fine until I started trying to push the task to be faster or add a set_timeout(). Initially with the set_timeout() issue my ioResponses were becoming out of sync after a timeoutError, I looked into #333 and thought maybe I should not be using add_callback and attempted to switch to wait()... However, whenever I use wait() my application seems to get stuck waiting for request_io() to complete. I recently switched back to using add_callback() and find it much more useful (even if I cant use a timeout when setting a callback) but don't like the fact that the fact that the application will continue on to the next task before the callback function completes. Essentially is there a way to guarantee:
will always print "completing callback function" before "on to next task"? (also help with add_timeout would be appreciated!) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The callback function is only called when the request has been completely processed by the controller, before that it might be sitting in a queue or only be partially processed. When you give an iocb to a controller it is no longer yours, like a buffer that you have given to the old school If an IOController has been given an IOCB instance, then in theory it is also responsible for doing whatever needs to happen when the request has been aborted, but given the nature of the client and server transaction state machines that manage the state of a request/response "transaction" that's been hard to get right. Using the I know exactly what you're looking for: In the mean time, check out the DiscoverToDo.py sample application with the |
Beta Was this translation helpful? Give feedback.
The callback function is only called when the request has been completely processed by the controller, before that it might be sitting in a queue or only be partially processed. When you give an iocb to a controller it is no longer yours, like a buffer that you have given to the old school
fgets()
andfputs()
stdio functions. You can look at the status code (polling-like) and do something with the results, pass a callback like you are doing now, or in a multi-threaded application - - not recommended - - callwait()
and your thread will be suspended until the event (semaphore) is set (signaled).If an IOController has been given an IOCB instance, then in theory it is also responsible for d…