Skip to content

Commit 20d93ae

Browse files
committed
working with fake-sensor
1 parent 895d02c commit 20d93ae

2 files changed

Lines changed: 27 additions & 22 deletions

File tree

yaqd-core/yaqd_core/_is_daemon.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,14 @@ def main(cls):
192192
# Run the event loop
193193
try:
194194
asyncio.run(cls._main(config_filepath, config_file, args))
195-
except asyncio.CancelledError:
196-
pass
195+
except KeyboardInterrupt:
196+
asyncio.run(cls.shutdown_all(signal.SIGINT, loop=cls.loop))
197197

198198
@classmethod
199199
async def _main(cls, config_filepath, config_file, args=None):
200200
"""Parse command line arguments, run event loop."""
201201
loop = asyncio.get_running_loop()
202+
cls.loop = loop
202203
if sys.platform.startswith("win"):
203204
signals = ()
204205
else:
@@ -208,27 +209,24 @@ async def _main(cls, config_filepath, config_file, args=None):
208209
s, lambda s=s: asyncio.create_task(cls.shutdown_all(s, loop))
209210
)
210211

211-
try:
212+
cls.__servers = set()
213+
for section in config_file:
214+
if section == "shared-settings":
215+
continue
216+
try:
217+
config = cls._parse_config(config_file, section, args)
218+
except ValueError as e:
219+
logger.error(str(e))
220+
continue
221+
logger.debug(f"Starting {section} with {config}")
222+
await cls._start_daemon(section, config, config_filepath)
223+
224+
while cls.__servers:
225+
awaiting = cls.__servers
212226
cls.__servers = set()
213-
for section in config_file:
214-
if section == "shared-settings":
215-
continue
216-
try:
217-
config = cls._parse_config(config_file, section, args)
218-
except ValueError as e:
219-
logger.error(str(e))
220-
continue
221-
logger.debug(f"Starting {section} with {config}")
222-
await cls._start_daemon(section, config, config_filepath)
223-
224-
while cls.__servers:
225-
awaiting = cls.__servers
226-
cls.__servers = set()
227-
await asyncio.wait(awaiting)
228-
await asyncio.sleep(1)
229-
loop.stop()
230-
except KeyboardInterrupt: # handle windows ctrl+c
231-
await cls.shutdown_all(signal.SIGINT, loop)
227+
await asyncio.wait(awaiting)
228+
await asyncio.sleep(1)
229+
loop.stop()
232230

233231
@classmethod
234232
async def _start_daemon(cls, name, config, config_filepath):

yaqd-fakes/yaqd_fakes/_fake_sensor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ async def _update_measurements(self):
3939
out["measurement_id"] = self._measurement_id
4040
self._measured = out
4141
await asyncio.sleep(self._config["update_period"])
42+
43+
async def aclose(self):
44+
await asyncio.sleep(0.1)
45+
self.logger.info("finished async close routine")
46+
47+
def close(self):
48+
asyncio.get_running_loop().create_task(self.aclose())

0 commit comments

Comments
 (0)