bugfix Thread close process

This commit is contained in:
misyaguziya
2023-06-15 03:18:05 +09:00
parent cb5b4f4e49
commit edefa119e9
2 changed files with 94 additions and 80 deletions

View File

@@ -1,5 +1,6 @@
import json
import datetime
import threading
def save_json(path, key, value):
with open(path, "r") as fp:
@@ -14,4 +15,19 @@ def print_textbox(textbox, message):
textbox.configure(state='normal')
textbox.insert("end", f"[{now}]{message}\n")
textbox.configure(state='disabled')
textbox.see("end")
textbox.see("end")
class thread_fnc(threading.Thread):
def __init__(self, fnc, *args, **kwargs):
super(thread_fnc, self).__init__(*args, **kwargs)
self.fnc = fnc
self._stop = threading.Event()
def stop(self):
self._stop.set()
def stopped(self):
return self._stop.isSet()
def run(self):
while True:
if self.stopped():
return
self.fnc()