asyncioをthreadingに置き換える

This commit is contained in:
suti7yk5032 2024-09-26 17:26:48 +09:00
parent 1cd58404c6
commit 885f625403

View file

@ -10,6 +10,8 @@ import random
import hashlib
import openpyxl
from openpyxl import Workbook
import threading
import time
class DL():
def __init__(self):
@ -769,9 +771,13 @@ class Monitor():
self.fstop_time = kwargs["fstop_time"]
self.init_wait_time = 10
async def search(self):
def start(self, **kwargs):
search_thread = threading.Thread(target=self.search)
search_thread.start()
def search(self):
try:
asyncio.sleep(self.init_wait_time)
time.sleep(self.init_wait_time)
while True:
cursor = dislocker.db.cursor()
cursor.execute("SELECT * FROM pc_list WHERE password_hash IS NOT NULL")
@ -833,7 +839,7 @@ class Monitor():
pass
else:
pass
asyncio.sleep(self.search_frequency)
time.sleep(self.search_frequency)
except Exception as error:
@ -1150,15 +1156,10 @@ async def button_init(interaction: discord.Interaction, text_channel: discord.Te
await interaction.response.send_message(f":white_check_mark: ボタンを送信しました!", ephemeral=True)
async def run():
if dislocker.init_result == "ok":
print("Botを起動します...")
monitor = Monitor(search_frequency=dislocker.server_config["bot"]["monitor"]["search_frequency"], allowable_time=dislocker.server_config["bot"]["monitor"]["allowable_time"], fstop_time=dislocker.server_config["bot"]["monitor"]["fstop_time"])
monitor_task = asyncio.create_task(monitor.search())
client_task = asyncio.create_task(client.run(dislocker.server_config["bot"]["token"]))
await asyncio.gather(monitor_task, client_task)
if dislocker.init_result == "ok":
asyncio.run(run())
monitor.start()
client.run(dislocker.server_config["bot"]["token"])
else:
pass
pass