Многопоточная работа с аккаунтами telethon
Всем здравствуйте! Не могу разобраться: не получается запустить мой скрипт, в котором сообщение должно отправляться с нескольких аккаунтов одновременно. Выдает длинную ошибку, не могу понять в чем дело. Прикрепляю скрипт:
import time
from threading import Thread
from telethon import TelegramClient, sync
import asyncio
api_hash = '1cccb9434e585aeхххb29d4ab8ххх504'
api_id = 19910ххх
usernamed = '@юзернейм'
def sleepMe(i):
client = TelegramClient(f'accounts/account{str(i)}', api_id=api_id, api_hash=api_hash, app_version="10 P (28)", device_model="Iphone", system_version='6.12.0')
client.start()
client.send_message(usernamed, '/start')
client.disconnect()
for i in range(5):
th = Thread(target=sleepMe, args=(i, ))
th.start()
Содержание ошибки:
Exception in thread Exception in thread Exception in thread Thread-1Thread-2Thread-3:
:
:
Exception in thread Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
Thread-4 File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
:
Traceback (most recent call last):
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
self.run()self.run()
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run
self.run()self.run()
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run
self._target(*self._args, **self._kwargs)self._target(*self._args, **self._kwargs)
File "c:\Users\WNPKV\Desktop\TEST\potoki.py", line 13, in sleepMe
File "c:\Users\WNPKV\Desktop\TEST\potoki.py", line 13, in sleepMe
self._target(*self._args, **self._kwargs)self._target(*self._args, **self._kwargs)client = TelegramClient(f'accounts/account{str(i)}', api_id=api_id, api_hash=api_hash, app_version="10 P (28)", device_model="Iphone", system_version='6.12.0')
File "c:\Users\WNPKV\Desktop\TEST\potoki.py", line 13, in sleepMe
File "c:\Users\WNPKV\Desktop\TEST\potoki.py", line 13, in sleepMe
client = TelegramClient(f'accounts/account{str(i)}', api_id=api_id, api_hash=api_hash, app_version="10 P (28)", device_model="Iphone", system_version='6.12.0') File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\telegrambaseclient.py", line 320, in __init__
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\telegrambaseclient.py", line 320, in __init__
client = TelegramClient(f'accounts/account{str(i)}', api_id=api_id, api_hash=api_hash, app_version="10 P (28)", device_model="Iphone", system_version='6.12.0')client = TelegramClient(f'accounts/account{str(i)}', api_id=api_id, api_hash=api_hash, app_version="10 P (28)", device_model="Iphone", system_version='6.12.0')
if not callable(getattr(self.loop, 'sock_connect', None)): File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\telegrambaseclient.py", line 320, in __init__
if not callable(getattr(self.loop, 'sock_connect', None)): File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\telegrambaseclient.py", line 320, in __init__
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\telegrambaseclient.py", line 472, in loop
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\telegrambaseclient.py", line 472, in loop
if not callable(getattr(self.loop, 'sock_connect', None)):
if not callable(getattr(self.loop, 'sock_connect', None)): File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\telegrambaseclient.py", line 472, in loop
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\telegrambaseclient.py", line 472, in loop
return asyncio.get_event_loop()
return asyncio.get_event_loop()
return asyncio.get_event_loop() File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\asyncio\events.py", line 642, in get_event_loop
Exception in thread File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\asyncio\events.py", line 642, in get_event_loop
Thread-5:
return asyncio.get_event_loop() File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\asyncio\events.py", line 642, in get_event_loop
Traceback (most recent call last):
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner
raise RuntimeError('There is no current event loop in thread %r.' File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\asyncio\events.py", line 642, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
raise RuntimeError('There is no current event loop in thread %r.'RuntimeError
RuntimeError: self.run(): There is no current event loop in thread 'Thread-2'. RuntimeError
There is no current event loop in thread 'Thread-1'.
raise RuntimeError('There is no current event loop in thread %r.': File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\threading.py", line 892, in run
There is no current event loop in thread 'Thread-3'.RuntimeError
: There is no current event loop in thread 'Thread-4'.
self._target(*self._args, **self._kwargs)
File "c:\Users\WNPKV\Desktop\TEST\potoki.py", line 13, in sleepMe
client = TelegramClient(f'accounts/account{str(i)}', api_id=api_id, api_hash=api_hash, app_version="10 P (28)", device_model="Iphone", system_version='6.12.0')
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\telegrambaseclient.py", line 320, in __init__
if not callable(getattr(self.loop, 'sock_connect', None)):
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\site-packages\telethon\client\telegrambaseclient.py", line 472, in loop
return asyncio.get_event_loop()
File "C:\Users\WNPKV\AppData\Local\Programs\Python\Python39\lib\asyncio\events.py", line 642, 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-5'.