This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove thread macanism because python does not support it well => go …
…full asyncio
- Loading branch information
Rodriguez
committed
Oct 22, 2023
1 parent
73d86c3
commit 2616598
Showing
7 changed files
with
173 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import asyncio | ||
|
||
# --- | ||
|
||
class MonitoredEventLoop(asyncio.SelectorEventLoop): | ||
"""Event loop that provide some load metric | ||
""" | ||
|
||
# --- | ||
|
||
def __init__(self, log, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self._total_time = 0 | ||
self._select_time = 0 | ||
|
||
self._before_select = None | ||
|
||
self.log = log | ||
self.perf_cycle_time = 2 | ||
|
||
self.log.info(f"EVENT LOOP UP !!") | ||
|
||
# --- | ||
|
||
# TOTAL TIME: | ||
def run_forever(self): | ||
self.ref_time = self.time() | ||
try: | ||
self.log.info(f"EVENT LOOP RUN") | ||
super().run_forever() | ||
finally: | ||
finished = self.time() | ||
# self._total_time = finished - started | ||
|
||
# --- | ||
|
||
# SELECT TIME: | ||
def _run_once(self): | ||
# print("_run_once") | ||
self._before_select = self.time() | ||
super()._run_once() | ||
|
||
# --- | ||
|
||
def _process_events(self, *args, **kwargs): | ||
after_select = self.time() | ||
self._select_time += after_select - self._before_select | ||
|
||
# print("_process_events", args, kwargs) | ||
super()._process_events(*args, **kwargs) | ||
|
||
cycle_time = self.time() - self.ref_time | ||
self.log.info(f"EVENT {cycle_time}") | ||
if cycle_time >= self.perf_cycle_time: | ||
|
||
work_time = cycle_time - self._select_time | ||
self.load = round((work_time/self.perf_cycle_time) * 100.0, 3) | ||
if self.load > 60: | ||
self.log.info(f"loop load {self.load}% !!") | ||
else: | ||
self.log.info(f"{self.load}%") | ||
self._select_time = 0 | ||
self.ref_time = self.time() | ||
|
||
# --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
|
||
from .drv_hanmatek_hm310t_ammeter import DriverHM310tAmmeter | ||
from .drv_panduza_fake_ammeter import DriverFakeAmmeter | ||
|
||
|
||
PZA_DRIVERS_LIST=[ | ||
DriverHM310tAmmeter, | ||
DriverFakeAmmeter | ||
DriverHM310tAmmeter | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters