Skip to content
Snippets Groups Projects
Commit 77857a80 authored by Stefano Di Frischia's avatar Stefano Di Frischia
Browse files

L2SS-1264: remove thread entries

parent 5d0a029a
No related branches found
No related tags found
1 merge request!559Draft: L2SS-1264: create async lofar device
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
from json import loads from json import loads
from statistics import median from statistics import median
# from threading import Thread, Lock, Condition
import asyncio import asyncio
from typing import Callable from typing import Callable
import datetime import datetime
...@@ -547,7 +546,7 @@ class BeamTracker: ...@@ -547,7 +546,7 @@ class BeamTracker:
"""""" """"""
self.done = False self.done = False
self.thread = None self.loop = None
self.interval = interval self.interval = interval
self.preparation_time = preparation_time self.preparation_time = preparation_time
...@@ -556,8 +555,6 @@ class BeamTracker: ...@@ -556,8 +555,6 @@ class BeamTracker:
self.fault_callback = fault_callback self.fault_callback = fault_callback
# Condition to trigger a forced update or early abort # Condition to trigger a forced update or early abort
# self.update_lock = Lock()
# self.update_condition = Condition(self.update_lock)
self.update_lock = asyncio.Lock() self.update_lock = asyncio.Lock()
self.update_condition = asyncio.Condition(self.update_lock) self.update_condition = asyncio.Condition(self.update_lock)
...@@ -571,20 +568,18 @@ class BeamTracker: ...@@ -571,20 +568,18 @@ class BeamTracker:
async def start(self): async def start(self):
"""Starts the Beam Tracking thread""" """Starts the Beam Tracking thread"""
if self.thread: if self.loop:
# already started # already started
return return
# self.thread = Thread(target=self._update_pointing_direction, name="BeamTracker") self.loop = asyncio.get_event_loop()
# self.thread.start() self.loop.create_task(self._update_pointing_direction())
loop = asyncio.get_event_loop()
loop.create_task(self._update_pointing_direction())
logger.info("[BeamTracking] Thread started") logger.info("[BeamTracking] Thread started")
async def is_alive(self) -> bool: async def is_alive(self) -> bool:
"""True just before and after run method starts and terminates""" """True just before and after run method starts and terminates"""
return self.thread and self.thread.is_alive() return self.loop and (self._update_pointing_direction() in asyncio.all_tasks())
async def force_update(self): async def force_update(self):
"""Force the pointing to be updated.""" """Force the pointing to be updated."""
...@@ -600,21 +595,21 @@ class BeamTracker: ...@@ -600,21 +595,21 @@ class BeamTracker:
async def stop(self): async def stop(self):
"""Stops the Beam Tracking loop""" """Stops the Beam Tracking loop"""
if not self.thread: if not self.loop:
return return
logger.info("[BeamTracking] Thread stopping") logger.info("[BeamTracking] Thread stopping")
self.done = True self.done = True
self.force_update() await self.force_update()
# wait for thread to finish # wait for thread to finish
self.thread.join(self.DISCONNECT_TIMEOUT) self.loop.run_until_complete(self._update_pointing_direction())
if self.is_alive(): if self.is_alive():
logger.error("[BeamTracking] Thread did not properly terminate") logger.error("[BeamTracking] Thread did not properly terminate")
self.thread = None self.loop = None
logger.info("[BeamTracking] Thread stopped") logger.info("[BeamTracking] Thread stopped")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment