12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- '''Created 16 Nov 2022 Levi'''
- from collections import deque
- from threading import Event
- from threading import Thread
- from time import sleep
- import asyncio
- import mail_alert
- # event1 = Event()
- # event2 = Event()
- # event3 = Event()
- # thread1 = Thread(target=mail_alert.mail_alert, args=(event1,))
- # thread2 = Thread(target=mail_alert.mail_alert2, args=(event2,))
- # thread3 = Thread(target=mail_alert.mail_alert3, args=(event3,))
- # thread4 =
- # thread5 =
- # thread6 =
- async def main() -> None:
- container: set = set()
- try:
- while True:
- # loop = asyncio.get_event_loop()
- # tasks = map(asyncio.create_task,
- # [mail_alert.mail_alert(container)
- # # mail_alert.mail_alert2()
- # # mail_alert.mail_alert3()
- # ])
- tasks = [mail_alert.mail_alert(container),
- mail_alert.mail_alert2(container),
- mail_alert.mail_alert3(container)]
- # result = await asyncio.wait(tasks)
- results = await asyncio.gather(*tasks)
- # print(result)
- for result in results:
- if result not in container:
- container.add(result)
- # await asyncio.sleep(1)
- except KeyboardInterrupt:
- print('Cancelling all tasks...')
- for task in tasks:
- task.cancel() # noqa
- await asyncio.gather(*tasks, return_exceptions=True)
- print('All tasks cancelled.')
- if __name__ == '__main__':
- asyncio.run(main())
|