Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vs4vijay committed Sep 13, 2020
1 parent fb0d75d commit e87ade6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
```

Expand All @@ -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"))
Expand Down
35 changes: 32 additions & 3 deletions telegram/gui/telegram_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

0 comments on commit e87ade6

Please sign in to comment.