asyncioをthreadingに置き換える
This commit is contained in:
parent
1cd58404c6
commit
885f625403
1 changed files with 13 additions and 12 deletions
|
@ -10,6 +10,8 @@ import random
|
||||||
import hashlib
|
import hashlib
|
||||||
import openpyxl
|
import openpyxl
|
||||||
from openpyxl import Workbook
|
from openpyxl import Workbook
|
||||||
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
class DL():
|
class DL():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -769,9 +771,13 @@ class Monitor():
|
||||||
self.fstop_time = kwargs["fstop_time"]
|
self.fstop_time = kwargs["fstop_time"]
|
||||||
self.init_wait_time = 10
|
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:
|
try:
|
||||||
asyncio.sleep(self.init_wait_time)
|
time.sleep(self.init_wait_time)
|
||||||
while True:
|
while True:
|
||||||
cursor = dislocker.db.cursor()
|
cursor = dislocker.db.cursor()
|
||||||
cursor.execute("SELECT * FROM pc_list WHERE password_hash IS NOT NULL")
|
cursor.execute("SELECT * FROM pc_list WHERE password_hash IS NOT NULL")
|
||||||
|
@ -833,7 +839,7 @@ class Monitor():
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
asyncio.sleep(self.search_frequency)
|
time.sleep(self.search_frequency)
|
||||||
|
|
||||||
|
|
||||||
except Exception as error:
|
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)
|
await interaction.response.send_message(f":white_check_mark: ボタンを送信しました!", ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
async def run():
|
if dislocker.init_result == "ok":
|
||||||
print("Botを起動します...")
|
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 = 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())
|
monitor.start()
|
||||||
client_task = asyncio.create_task(client.run(dislocker.server_config["bot"]["token"]))
|
client.run(dislocker.server_config["bot"]["token"])
|
||||||
await asyncio.gather(monitor_task, client_task)
|
|
||||||
|
|
||||||
|
|
||||||
if dislocker.init_result == "ok":
|
|
||||||
asyncio.run(run())
|
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue