Question: Is there a way to detect a pause in data reception?
betov75 opened this issue · 1 comments
betov75 commented
Hi! I need to detect when data stops entering for at least X ms. For example, when data is entering, if, for example, 300 ms passed between two lines, a function is launched. Can this jeopardize the perofmrnance a lot?
Thank you very much for your answer(s)
attwad commented
You could either:
- keep track of the last time a handler was called (assuming you catch all incoming events) and update that time in each handler as well as check for the duration you want.
- start a timer that you'd cancel/restart on each handler, there are many ways to do that depending on the way you run your program (sched-based, signal.alarm based, threading.Timer based etc, read through those and pick the one you want)
Neither option should really be costing much, just make sure you're not blocking (never call time.sleep
).