import asyncio
import asyncpg
# from config import ConfServer
import time
import concurrent.futures
from dataclasses import dataclass
import struct
@dataclass(order=True)
class ConfServer:
db_user: str = "admin"
db_password: str = 'vrqegtq4r23ewqs'
db_name: str = 'chat'
db_host: str = 'localhost'
config = ConfServer()
async def readmsg(reader):
d = await asyncio.wait_for(reader.readexactly(4), timeout=30)
d = struct.unpack('>I', d)[0]
d = await asyncio.wait_for(reader.readexactly(d), timeout=30)
d = d.decode("utf-8")
if d == "pong":
return "pong"
return d
def time_sleep():
if False:
time.sleep(5)
async def close_ppool(pool):
try:
await pool.close()
print('create_pool close')
except:
print('except pool.close')
time_sleep()
async def run():
while True:
try:
print('start create_pool')
pool = await asyncpg.create_pool(user=config.db_user,
password=config.db_password,
database=config.db_name,
host=config.db_host)
except:
print('except create_pool')
time_sleep()
continue
try:
print('start open_connection')
reader, writer = await asyncio.open_connection('localhost', 9990)
except OSError as e:
print("OSError : tcp_client_start")
time_sleep()
await close_ppool(pool)
continue
writer.write(struct.pack('>I', 4) + 'ping'.encode("utf-8"))
data = await readmsg(reader)
print("DATA <<<: " + str(data) + "\n")
writer.close()
await writer.wait_closed()
await close_ppool(pool)
time.sleep(5)
loop = asyncio.get_event_loop()
loop.set_default_executor(concurrent.futures.ThreadPoolExecutor(max_workers=0))
loop.run_until_complete(run())
pool= await asyncpg.create_pool()
await self.pool.close()потоки почему то не умирают а так же висят в трее в htop.
nameserver 192.168.1.1
nameserver 8.8.8.8
Доступ к информационному ресурсу ограничен на основании ФЗ от 27.07.2006 г. №149-ФЗ "Об информации, информационных технологиях и о защите информации"
client = TelegramClient("sdssdswvrewqf", config_f["id"], config_f["hash"])
client.start()
client.connect()
print( client.get_entity(PeerUser(615435914)))
ValueError: Could not find the input entity for "PeerUser(user_id=615435914)". Please read https://telethon.readthedocs.io/en/latest/extra/ba... to find out more details.