Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
nootalp committed Oct 23, 2023
1 parent 6b34750 commit e7734ed
Showing 3 changed files with 79 additions and 0 deletions.
Binary file modified README.md
Binary file not shown.
26 changes: 26 additions & 0 deletions Stome.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import asyncio
from abc import ABC, abstractmethod


class Run(ABC):

def __init__(self, event):
self._name = self.__class__.__name__
self._event = event

async def __aenter__(self):
print(f"Initiating {self._name, self._event}")
return self

async def __aexit__(self, exc_type, exc, tb):
if exc_type is not None:
print(f"Exception {exc_type} in {self._name}. {exc}")
return True

async def return_value(self, event):
print(f"{'True' if event.is_set() else 'False'} from {self._name}")
await asyncio.sleep(1)

@abstractmethod
def task(self, event):
pass
53 changes: 53 additions & 0 deletions Test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from Stome import Run
import asyncio
import msvcrt
import keyboard


class Test1(Run):

async def task(self, event):
while True:
await self.return_value(event)
await event.wait()


class Test2(Run):

async def task(self, event):
while True:
await self.return_value(event)
await event.wait()


class Key(Run):

async def task(self, event):
while True:
is_pressed = keyboard.is_pressed(hotkey="insert")
if is_pressed and not _was_pressed:
event.clear() if event.is_set() else event.set()
print("Switch state:", event.is_set())

_was_pressed = is_pressed
await asyncio.sleep(0.1)


async def main():
halt = asyncio.Event()
subclasses = [globals()[index.__name__] for index in Run.__subclasses__()]

async with asyncio.TaskGroup() as group:
for Class in subclasses:
instance = Class(halt)
async with instance:
group.create_task(instance.task(halt))


try:
asyncio.run(main())
except KeyboardInterrupt:
pass
finally:
while msvcrt.kbhit():
msvcrt.getch()

0 comments on commit e7734ed

Please sign in to comment.