From e87ade6ffdb32e08e12426c6b66052f11df59d9d Mon Sep 17 00:00:00 2001 From: vs4vijay Date: Sun, 13 Sep 2020 14:54:02 +0530 Subject: [PATCH] changes --- README.md | 34 ++++++++++++++++++++++++++++++++++ telegram/gui/telegram_gui.py | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 08d4494..cc5b8de 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,38 @@ import sys sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) +loop.create_task(client.send_message('TelethonOfftopic', 'Hey guys!')) + +pending = asyncio.Task.all_tasks() + + + + loop = asyncio.get_event_loop() + blocking_tasks = [ + loop.run_in_executor(executor, blocks, i) + for i in range(6) + ] + log.info('waiting for executor tasks') + completed, pending = await asyncio.wait(blocking_tasks) + results = [t.result() for t in completed] + log.info('results: {!r}'.format(results)) + + + +import threading + +def fire_and_forget(f): + def wrapped(): + threading.Thread(target=f).start() + + return wrapped + +@fire_and_forget +def foo(): + time.sleep(1) + print("foo() completed") + + ``` @@ -221,6 +253,8 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..') ``` + + pip3 install PyQt5==5.11.3 # self.setWindowIcon(QtGui.QIcon("icon.png")) diff --git a/telegram/gui/telegram_gui.py b/telegram/gui/telegram_gui.py index 4d64d67..2fc2f9a 100755 --- a/telegram/gui/telegram_gui.py +++ b/telegram/gui/telegram_gui.py @@ -249,8 +249,34 @@ async def join_channels(self): return results = {} - for channel in channels: - results[channel] = await bot.join_channel(channel) + + try: + for channel in channels: + # results[channel] = await bot.join_channel(channel) + # loop1 = asyncio.get_event_loop() # get the default loop for the main thread + # await self.loop.create_task(bot.join_channel(channel)) + self.loop.run_in_executor(None, bot.join_channel, [channel]) + # loop1.run_until_complete() + except Exception as e: + print(f'------- Exception {e} - {sys.exc_info()}') + pass + + + # pending = asyncio.Task.all_tasks() + # print('pending takssss') + # print(pending) + # self.loop.run_until_complete(asyncio.gather(*pending)) + + # print('---- Killing tasks') + # pending = asyncio.Task.all_tasks() + # print('pending takssss') + # print(pending) + # for task in pending: + # print('task ') + # print(task) + # task.cancel() + # with suppress(asyncio.CancelledError): + # self.loop.run_until_complete(task) logger.info('join_channels results') logger.info(results) @@ -361,7 +387,10 @@ def main_gui(): ex.show() with loop: - sys.exit(loop.run_forever()) + print('------- in with loop') + sys.exit(loop.run_forever()) + + if __name__ == '__main__': main_gui()