Telethon: Document asyncio better

Created on 25 Nov 2017  Â·  12Comments  Â·  Source: LonamiWebs/Telethon

Maybe I'm missing something obvious, but this code:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from telethon import TelegramClient

api_id = *****
api_hash = '*****************'
phone = '********'

client = TelegramClient('session_name', api_id, api_hash)
client.connect()

Yields this error:

$ ./tg.py 
./tg.py:10: RuntimeWarning: coroutine 'TelegramBareClient.connect' was never awaited
  client.connect()

I'm using Python 3.5.2.

Python 3.5.2 (default, Sep 14 2017, 22:51:06) 
[GCC 5.4.0 20160609] on linux

Most helpful comment

Sorry for not having infinite time to work on a project I maintain for fun.

All 12 comments

Well then await it. await client.connect().

You definitely should add some info about it to the docs and examples.

Sorry for not having infinite time to work on a project I maintain for fun.

But yeah as a more serious answer, I'm not that experienced enough with asyncio. I just git merge master to it from time to time and add the corresponding async/await keywords. The question you asked though was somewhat obvious. Looking for the error in the internet would have yield a better, less rude answer. Async calls must be awaited, otherwise, they're never actually ran.

Uhm, no offence. As my first step, I just took some code from readme.rst to make sure I use 120% valid code, and it didn't work. So I think it's worth mentioning (at least) something about asyncio and coroutines.

And I'm not pressing or urging you, I just opened an issue in a _issue tracker_. Because that's what you do when you find a issue, isn't it? I can even rename it, if you want ¯_(ツ)_/¯

Sorry I think I pushed asyncio to PyPi instead the master branch. I've pushed 0.15.3.3 to PyPi to solve this.

Yeah, I should have mentioned the package version I was using (PyPi 0.15.5.2). Anyway, I think this issue is resolved.

@Lonami what is the plan for asyncio support? I see you have a development branch for it, but is it planned to be integrated in some release, subsituting old interface or what?

Both will coexist because replacing master with asyncio would be a big breaking change and I don't like asyncio anyway. I'll try to keep said branch up to date so you can install that if you want.

Mostly added enough to show how to run event loops and await keywords where needed (which should be enough). Also worked to find out and fix https://github.com/LonamiWebs/Telethon/commit/5cb3a9af36b69efb249da891b8136eab5a5ec520.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

saeedesfandi picture saeedesfandi  Â·  3Comments

chri1389 picture chri1389  Â·  6Comments

Humphry150 picture Humphry150  Â·  3Comments

aminhyper picture aminhyper  Â·  3Comments

Lerbytech picture Lerbytech  Â·  5Comments