Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Asyncio set event loop make freeze

I am creating an application in python and i need to create channel with telegram, for make this, i use telethon:

async def createChannel(username, desc):
try:
    chn = await client(CreateChannelRequest(username,desc,megagroup=False))
    new_channel_id = chn.chats[0].id
    new_channel_access_hash = chn.chats[0].access_hash
    update_response = await client(UpdateUsernameRequest(
            InputPeerChannel(channel_id=new_channel_id,
                            access_hash=new_channel_access_hash), username))
except:
    await client.connect()
    chn = await client(CreateChannelRequest(username,desc,megagroup=False))
    new_channel_id = chn.chats[0].id
    new_channel_access_hash = chn.chats[0].access_hash
    update_response = await client(UpdateUsernameRequest(
            InputPeerChannel(channel_id=new_channel_id,
                            access_hash=new_channel_access_hash), username))
return update_response

I want to use multi threading but when i do that, i got error that say me "No event loop in the thread", so ask google and he gave me this:

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

But when i have this and my multi threading, it just stuck and do nothing at this line:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

chn = await client(CreateChannelRequest(username,desc,megagroup=False))

Any idea? thx 🙂

>Solution :

When initializing the client object, you should pass the event loop to TelegramClient like:

from telethon import TelegramClient

loop = asyncio.new_event_loop()
client = TelegramClient(..., loop=loop)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading