11# Licensed under the GPLv3 License: https://www.gnu.org/licenses/gpl-3.0.html
22# For details: https://github.com/muziing/Py2exe-GUI/blob/main/README.md#license
33
4- import os . path
4+ from pathlib import Path
55from sys import getdefaultencoding
6- from typing import Optional , Sequence
6+ from typing import Optional , Sequence , Union
77
88from PySide6 .QtCore import QIODeviceBase , QObject , QProcess , Signal
99
@@ -52,10 +52,13 @@ def start_process(
5252 self ,
5353 * ,
5454 mode : QIODeviceBase .OpenModeFlag = QIODeviceBase .OpenModeFlag .ReadWrite ,
55- ) -> None :
55+ time_out : int = 1000 ,
56+ ) -> bool :
5657 """
5758 创建并启动子进程 \n
5859 :param mode: 设备打开的模式
60+ :param time_out: 启动进程超时时间(单位为毫秒)
61+ :return: 是否成功启动
5962 """
6063
6164 if self ._process is None : # 防止在子进程运行结束前重复启动
@@ -70,9 +73,10 @@ def start_process(
7073
7174 self ._process .setWorkingDirectory (self ._working_directory )
7275 self ._process .start (self .program , self ._arguments , mode )
73- self ._process .waitForStarted (1000 ) # 阻塞,直到启动了子进程或超时(单位为毫秒)
76+ return self ._process .waitForStarted (time_out ) # 阻塞,直到成功启动子进程或超时
77+ return False
7478
75- def abort_process (self , timeout : int = 10000 ) -> bool :
79+ def abort_process (self , timeout : int = 5000 ) -> bool :
7680 """
7781 终止子进程 \n
7882 :param timeout: 超时时间,单位为毫秒
@@ -96,15 +100,16 @@ def set_arguments(self, arguments: Sequence[str]) -> None:
96100
97101 self ._arguments = arguments
98102
99- def set_working_dir (self , work_dir : str ) -> bool :
103+ def set_working_dir (self , work_dir : Union [ str , Path ] ) -> bool :
100104 """
101105 设置子进程工作目录 \n
102106 :param work_dir: 工作目录
103107 :return: 是否设置成功
104108 """
105109
106- if os .path .isdir (work_dir ):
107- self ._working_directory = work_dir
110+ working_dir = Path (work_dir )
111+ if working_dir .is_dir ():
112+ self ._working_directory = str (working_dir .resolve ())
108113 return True
109114 else :
110115 return False
0 commit comments