2023-03-12, fix thread blocking issue on some special environment.

master
CHUN YU YAO 2023-03-14 08:28:24 +08:00
parent 54e976d457
commit 069ce7669b
3 changed files with 49 additions and 45 deletions

View File

@ -53,7 +53,7 @@ import argparse
import ssl import ssl
ssl._create_default_https_context = ssl._create_unverified_context ssl._create_default_https_context = ssl._create_unverified_context
CONST_APP_VERSION = u"MaxBot (2023.03.11)" CONST_APP_VERSION = u"MaxBot (2023.03.12)"
CONST_MAXBOT_CONFIG_FILE = "settings.json" CONST_MAXBOT_CONFIG_FILE = "settings.json"
CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt" CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt"

View File

@ -19,8 +19,10 @@ import platform
import json import json
import webbrowser import webbrowser
import base64 import base64
import threading
import subprocess
CONST_APP_VERSION = u"MaxBot (2023.03.11)" CONST_APP_VERSION = u"MaxBot (2023.03.12)"
CONST_MAXBOT_LAUNCHER_FILE = "config_launcher.json" CONST_MAXBOT_LAUNCHER_FILE = "config_launcher.json"
CONST_MAXBOT_CONFIG_FILE = "settings.json" CONST_MAXBOT_CONFIG_FILE = "settings.json"
@ -314,8 +316,9 @@ def btn_items_run_event(event):
btn_index = int(str(event.widget['text']).split(" ")[1]) btn_index = int(str(event.widget['text']).split(" ")[1])
global txt_file_name global txt_file_name
filename=txt_file_name[btn_index-1].get().strip() filename=txt_file_name[btn_index-1].get().strip()
threading.Thread(target=launch_maxbot, args=(filename,)).start()
import subprocess def launch_maxbot(filename):
if True: if True:
working_dir = os.path.dirname(os.path.realpath(__file__)) working_dir = os.path.dirname(os.path.realpath(__file__))
if hasattr(sys, 'frozen'): if hasattr(sys, 'frozen'):

View File

@ -22,8 +22,9 @@ import pyperclip
import base64 import base64
import time import time
import threading import threading
import subprocess
CONST_APP_VERSION = u"MaxBot (2023.03.11)" CONST_APP_VERSION = u"MaxBot (2023.03.12)"
CONST_MAXBOT_CONFIG_FILE = "settings.json" CONST_MAXBOT_CONFIG_FILE = "settings.json"
CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt" CONST_MAXBOT_LAST_URL_FILE = "MAXBOT_LAST_URL.txt"
@ -846,54 +847,55 @@ def btn_save_act(language_code, slience_mode=False):
def btn_run_clicked(language_code): def btn_run_clicked(language_code):
import subprocess
print('run button pressed.') print('run button pressed.')
Root_Dir = "" Root_Dir = ""
save_ret = btn_save_act(language_code, slience_mode=True) save_ret = btn_save_act(language_code, slience_mode=True)
print("save config result:", save_ret) print("save config result:", save_ret)
if save_ret: if save_ret:
working_dir = os.path.dirname(os.path.realpath(__file__)) threading.Thread(target=launch_maxbot).start()
if hasattr(sys, 'frozen'):
print("execute in frozen mode")
# check platform here. def launch_maxbot():
if platform.system() == 'Darwin': working_dir = os.path.dirname(os.path.realpath(__file__))
print("execute MacOS python script") if hasattr(sys, 'frozen'):
subprocess.Popen("./chrome_tixcraft", shell=True, cwd=working_dir) print("execute in frozen mode")
if platform.system() == 'Linux':
print("execute linux binary")
subprocess.Popen("./chrome_tixcraft", shell=True, cwd=working_dir)
if platform.system() == 'Windows':
print("execute .exe binary.")
subprocess.Popen("chrome_tixcraft.exe", shell=True, cwd=working_dir)
else:
interpreter_binary = 'python'
interpreter_binary_alt = 'python3'
if platform.system() == 'Darwin':
# try python3 before python.
interpreter_binary = 'python3'
interpreter_binary_alt = 'python'
print("execute in shell mode.")
#print("script path:", working_dir)
#messagebox.showinfo(title="Debug0", message=working_dir)
# some python3 binary, running in 'python' command. # check platform here.
if platform.system() == 'Darwin':
print("execute MacOS python script")
subprocess.Popen("./chrome_tixcraft", shell=True, cwd=working_dir)
if platform.system() == 'Linux':
print("execute linux binary")
subprocess.Popen("./chrome_tixcraft", shell=True, cwd=working_dir)
if platform.system() == 'Windows':
print("execute .exe binary.")
subprocess.Popen("chrome_tixcraft.exe", shell=True, cwd=working_dir)
else:
interpreter_binary = 'python'
interpreter_binary_alt = 'python3'
if platform.system() == 'Darwin':
# try python3 before python.
interpreter_binary = 'python3'
interpreter_binary_alt = 'python'
print("execute in shell mode.")
#print("script path:", working_dir)
#messagebox.showinfo(title="Debug0", message=working_dir)
# some python3 binary, running in 'python' command.
try:
print('try', interpreter_binary)
s=subprocess.Popen([interpreter_binary, 'chrome_tixcraft.py'], cwd=working_dir)
#s=subprocess.Popen(['./chrome_tixcraft'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=working_dir)
#s=subprocess.run(['python3', 'chrome_tixcraft.py'], cwd=working_dir)
#messagebox.showinfo(title="Debug1", message=str(s))
except Exception as exc:
print('try', interpreter_binary_alt)
try: try:
print('try', interpreter_binary) s=subprocess.Popen([interpreter_binary_alt, 'chrome_tixcraft.py'], cwd=working_dir)
s=subprocess.Popen([interpreter_binary, 'chrome_tixcraft.py'], cwd=working_dir)
#s=subprocess.Popen(['./chrome_tixcraft'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=working_dir)
#s=subprocess.run(['python3', 'chrome_tixcraft.py'], cwd=working_dir)
#messagebox.showinfo(title="Debug1", message=str(s))
except Exception as exc: except Exception as exc:
print('try', interpreter_binary_alt) msg=str(exc)
try: print("exeption:", msg)
s=subprocess.Popen([interpreter_binary_alt, 'chrome_tixcraft.py'], cwd=working_dir) #messagebox.showinfo(title="Debug2", message=msg)
except Exception as exc: pass
msg=str(exc)
print("exeption:", msg)
#messagebox.showinfo(title="Debug2", message=msg)
pass
def btn_preview_sound_clicked(): def btn_preview_sound_clicked():
global txt_captcha_sound_filename global txt_captcha_sound_filename
@ -2549,7 +2551,6 @@ def load_GUI(root, config_dict):
AutofillTab(tab3, config_dict, language_code, UI_PADDING_X) AutofillTab(tab3, config_dict, language_code, UI_PADDING_X)
RuntimeTab(tab4, config_dict, language_code, UI_PADDING_X) RuntimeTab(tab4, config_dict, language_code, UI_PADDING_X)
AboutTab(tab5, language_code) AboutTab(tab5, language_code)
threading.Thread(target=settings_timer, daemon=True).start()
def main(): def main():
@ -2571,7 +2572,6 @@ def main():
load_GUI(root, config_dict) load_GUI(root, config_dict)
GUI_SIZE_WIDTH = 510 GUI_SIZE_WIDTH = 510
GUI_SIZE_HEIGHT = 619 GUI_SIZE_HEIGHT = 619
@ -2609,6 +2609,7 @@ def main():
root.call('wm', 'iconphoto', root._w, logo) root.call('wm', 'iconphoto', root._w, logo)
os.remove(icon_filepath) os.remove(icon_filepath)
threading.Thread(target=settings_timer, daemon=True).start()
root.mainloop() root.mainloop()
if __name__ == "__main__": if __name__ == "__main__":