Привет всем, Нужно запустить сразу несколько юзерботов в одно время. При использовании threading появляется такая ошибка:
spoilerException in thread Thread-1 (runner):
Traceback (most recent call last):
File "C:\Users\Atomniy-PC\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner
self.run()
File "C:\Users\Atomniy-PC\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Atomniy-PC\Desktop\projects\TgUserBot\main.py", line 20, in runner
c.run()
File "C:\Users\Atomniy-PC\Desktop\projects\TgUserBot\env\lib\site-packages\pyrogram\methods\utilities\run.py", line 73, in run
loop = asyncio.get_event_loop()
File "C:\Users\Atomniy-PC\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 656, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-1 (runner)'.
Exception in thread Thread-2 (runner):
Traceback (most recent call last):
File "C:\Users\Atomniy-PC\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner
self.run()
File "C:\Users\Atomniy-PC\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Atomniy-PC\Desktop\projects\TgUserBot\main.py", line 20, in runner
c.run()
File "C:\Users\Atomniy-PC\Desktop\projects\TgUserBot\env\lib\site-packages\pyrogram\methods\utilities\run.py", line 73, in run
loop = asyncio.get_event_loop()
File "C:\Users\Atomniy-PC\AppData\Local\Programs\Python\Python310\lib\asyncio\events.py", line 656, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-2 (runner)'.
Process finished
with exit code 0
Я так понимаю, это происходит по той причине, что функция запускается не в основном потоке, но как это исправить не могу понять..
import...
accounts = [app, app2]
async def echo(client, message):
await message.reply(message.text)
def runner(c):
c.run()
for ac in accounts:
ac.add_handler(handlers.MessageHandler(echo, filters.text & filters.private))
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
t = threading.Thread(target=runner, args=(ac,))
t.start()
t.join()