Telethon: RuntimeError: There is no current event loop in thread 'Thread-1'.

Created on 28 Jun 2018  路  33Comments  路  Source: LonamiWebs/Telethon

Sync version new

RuntimeError: There is no current event loop in thread 'Thread-1'.

client.get_messages(
            entity='@test',
            offset_id=2,
            limit=1
        )

Most helpful comment

There was a not that shouldn't have been there. https://github.com/LonamiWebs/Telethon/commit/872dfdd7d6db2d74008e5e41d5b60e4be96e2590 fixed it.

All 33 comments

telethon-sync package?

yes

pip install --no-cache --upgrade git+https://github.com/LonamiWebs/Telethon@sync

Installing collected packages: Telethon-sync
  Found existing installation: Telethon-sync 1.0.1
    Uninstalling Telethon-sync-1.0.1:
      Successfully uninstalled Telethon-sync-1.0.1
  Running setup.py install for Telethon-sync ... done
Successfully installed Telethon-sync-1.0.1
    return AsyncGenerator(coroutine_maker(*args, **kwargs))
  File "/Applications/MAMP/htdocs/local.loc/app/Console/Commands/Python/lib/python3.6/site-packages/telethon/client/messages.py", line 191, in iter_messages
    start = asyncio.get_event_loop().time()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py", line 694, in get_event_loop
    return get_event_loop_policy().get_event_loop()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py", line 602, in get_event_loop
    % threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'Thread-1'.

Oh, right, I know what it is.

pip install --no-cache --upgrade git+https://github.com/LonamiWebs/Telethon@sync

  File "/Applications/MAMP/htdocs/local.loc/app/Console/Commands/Python/lib/python3.6/site-packages/telethon/client/messages.py", line 274, in get_messages
    for x in self.iter_messages(*args, **kwargs):
  File "/Applications/MAMP/htdocs/local.loc/app/Console/Commands/Python/lib/python3.6/site-packages/async_generator/_impl.py", line 335, in async_generator_maker
    return AsyncGenerator(coroutine_maker(*args, **kwargs))
  File "/Applications/MAMP/htdocs/local.loc/app/Console/Commands/Python/lib/python3.6/site-packages/telethon/client/messages.py", line 246, in iter_messages
    max(wait_time - (time.time() - start), 0), loop=self._loop)
AttributeError: 'TelegramClient' object has no attribute '_loop'

Try now.

Any reason why you have to use telethon-sync by the way?

Newbie in python(
A lot of code is written, already(

Okay.

Can the whole project do a search on asyncio?

"Do a search"?

AttributeError: 'NoneType' object has no attribute '__await__'

Exception ignored in: <bound method AsyncGenerator.__del__ of <async_generator._impl.AsyncGenerator object at 0x10bbe4fd0>>
Traceback (most recent call last):
  File "/Applications/MAMP/htdocs/local.loc/app/Console/Commands/Python/lib/python3.6/site-packages/async_generator/_impl.py", line 315, in __del__
    if getcoroutinestate(self._coroutine) is CORO_CREATED:
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/inspect.py", line 1651, in getcoroutinestate
    if coroutine.cr_running:
AttributeError: 'NoneType' object has no attribute 'cr_running'

That's not for telethon-sync. I'm asking if running:

pip install --no-cache --upgrade git+https://github.com/LonamiWebs/Telethon@sync

Again has solved your problem or not?

  File "/Applications/MAMP/htdocs/local.loc/app/Console/Commands/Python/lib/python3.6/site-packages/telethon/client/messages.py", line 274, in get_messages
    for x in self.iter_messages(*args, **kwargs):
  File "/Applications/MAMP/htdocs/local.loc/app/Console/Commands/Python/lib/python3.6/site-packages/async_generator/_impl.py", line 335, in async_generator_maker
    return AsyncGenerator(coroutine_maker(*args, **kwargs))
  File "/Applications/MAMP/htdocs/local.loc/app/Console/Commands/Python/lib/python3.6/site-packages/async_generator/_impl.py", line 231, in __init__
    self._it = coroutine.__await__()
AttributeError: 'NoneType' object has no attribute '__await__'

Exception ignored in: <bound method AsyncGenerator.__del__ of <async_generator._impl.AsyncGenerator object at 0x10220bf60>>
Traceback (most recent call last):
  File "/Applications/MAMP/htdocs/local.loc/app/Console/Commands/Python/lib/python3.6/site-packages/async_generator/_impl.py", line 315, in __del__
    if getcoroutinestate(self._coroutine) is CORO_CREATED:
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/inspect.py", line 1651, in getcoroutinestate
    if coroutine.cr_running:
AttributeError: 'NoneType' object has no attribute 'cr_running'

Oh I see. Wow I'm so dense today :woman_facepalming:

Do you have stable branches?

Can you try again?

No there's no such thing as stable branches. Everything can at any moment have a bug.

    class MessageMethods(UploadMethods, MessageParseMethods):
  File "/Applications/MAMP/htdocs/local.loc/app/Console/Commands/Python/lib/python3.6/site-packages/telethon/client/messages.py", line 644, in MessageMethods
    @async_generator
NameError: name 'async_generator' is not defined

Well I forgot to remove those. Once more please?

yes, thank you, I hope the other did not fall off)

button_count return 0

buttons return list success

There was a not that shouldn't have been there. https://github.com/LonamiWebs/Telethon/commit/872dfdd7d6db2d74008e5e41d5b60e4be96e2590 fixed it.

Thank you)

@Lonami Excuse for troubling. I have a similar problem, the sync library is not available. The problem occurs only on the server, on the local machine everything is in order.

from telethon import TelegramClient

client = TelegramClient('session', api_id, api_hash)

async def main(argv):
    print(argv)
    msg = await client.send_file()
    await client.disconnect()
    return 0

def starter(data):
    with client:
        status = client.loop.run_until_complete(main(data))

@Lonami Using the new version of python, it seems, solved the problem, I will observe.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chri1389 picture chri1389  路  6Comments

pazis picture pazis  路  5Comments

Lerbytech picture Lerbytech  路  5Comments

JackCloudman picture JackCloudman  路  6Comments

rbabaee2014 picture rbabaee2014  路  3Comments