Commit 729ef892 authored by oroulet's avatar oroulet Committed by oroulet

improve accuracy of subscription loop timing

parent 04a85e2c
......@@ -4,6 +4,7 @@ server side implementation of a subscription object
import logging
import asyncio
import time
from typing import Union, Iterable, Dict, List
from asyncua import ua
......@@ -72,9 +73,15 @@ class InternalSubscription:
"""
Start the publication loop running at the RevisedPublishingInterval.
"""
ts = time.time()
period = self.data.RevisedPublishingInterval / 1000.0
try:
await self.publish_results()
while True:
await asyncio.sleep(self.data.RevisedPublishingInterval / 1000.0)
next_ts = ts + period
sleep_time = next_ts - time.time()
ts = next_ts
await asyncio.sleep(max(sleep_time, 0))
await self.publish_results()
except asyncio.CancelledError:
self.logger.info('exiting _subscription_loop for %s', self.data.SubscriptionId)
......
......@@ -48,7 +48,7 @@ async def main():
# subscribing to a variable node
handler = SubHandler()
sub = await client.create_subscription(500, handler)
sub = await client.create_subscription(10, handler)
handle = await sub.subscribe_data_change(myvar)
await asyncio.sleep(0.1)
......@@ -60,6 +60,8 @@ async def main():
# calling a method on server
res = await obj.call_method("2:multiply", 3, "klk")
_logger.info("method result is: %r", res)
while True:
await asyncio.sleep(1)
if __name__ == "__main__":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment