A
A
Akshin Yolchuev2020-08-16 14:55:43
Python
Akshin Yolchuev, 2020-08-16 14:55:43

Bug in Python threads?

I want to activate the function through flows, but the
code gives an error:

from threading import Thread as th
from telethon.sync import TelegramClient


def mama(num,idd,hashh):

    client = TelegramClient(num,idd,hashh)
    client.start()



p=th(target=mama,name='eew', args=('номер телефона',ид,'хэш'))
p.start()

mistake:
Exception in thread eew:
Traceback (most recent call last):
  File "C:\Python\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Python\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:/Users/hp/PycharmProjects/pythonProject/akshin/telegra.py", line 52, in mama
    client = TelegramClient(num,idd,hashh)
  File "C:\Python\lib\site-packages\telethon\client\telegrambaseclient.py", line 231, in init
    self._loop = asyncio.get_event_loop()
  File "C:\Python\lib\asyncio\events.py", line 639, in get_event_loop
    raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'eew'.

Process finished with exit code 0

Why is it giving this error and how to fix it?
P.S flows are obligatory as several flows will be connected.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-08-16
@bacon

It is a very dubious idea to use asyncio in threads, but if you really want to, then in each thread you need to create your own event loop, how much it will work, xs. And best of all, use processes. Of course, you should also read the docks https://docs.telethon.dev/en/latest/concepts/async...

threads are required as multiple threads will be connected.
what a wonderful causal relationship

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question