|
@@ -61,6 +61,7 @@ DWORD CPythonExecutor::_WorkerThread(LPVOID lpParam)
|
|
|
Sleep(2000);
|
|
|
// 结束日志线程;
|
|
|
that->m_bStopLogExport = TRUE;
|
|
|
+ // 可能出错:m_pCaseObj可能会提前释放了,所以需要保证不能提前释放;
|
|
|
GLOBAL::WriteTextLog(_T("脚本执行线程结束,用例名=%s"), that->m_pCaseObj->strCaseName.c_str());
|
|
|
|
|
|
return 0;
|
|
@@ -428,9 +429,9 @@ void CPythonExecutor::EndLogThread()
|
|
|
{
|
|
|
// 标记结束;
|
|
|
m_bStopLogExport = TRUE;
|
|
|
- // 等待3秒,是否能自主结束线程;
|
|
|
+ // 等待5秒,是否能自主结束线程;
|
|
|
if ( m_hStdoutLogThread ) {
|
|
|
- if ( WaitForSingleObject(m_hStdoutLogThread, 3000) == WAIT_OBJECT_0 ) {
|
|
|
+ if ( WaitForSingleObject(m_hStdoutLogThread, 5000) == WAIT_OBJECT_0 ) {
|
|
|
CloseHandle(m_hStdoutLogThread);
|
|
|
m_hStdoutLogThread = NULL;
|
|
|
}
|
|
@@ -438,19 +439,21 @@ void CPythonExecutor::EndLogThread()
|
|
|
|
|
|
// 手动结束线程;
|
|
|
if (m_hStdoutLogThread) {
|
|
|
- // 尝试5次结束行为;
|
|
|
- for (int i = 0; i < 5; i++) {
|
|
|
- if (TerminateThread(m_hStdoutLogThread, 0))
|
|
|
- break;
|
|
|
+ TerminateThread(m_hStdoutLogThread, 0);
|
|
|
+ // 异步结束,需要等待(5秒)系统完成操作;
|
|
|
+ if ( WaitForSingleObject(m_hStdoutLogThread, 5000) == WAIT_OBJECT_0 ) {
|
|
|
+ CloseHandle(m_hStdoutLogThread);
|
|
|
+ m_hStdoutLogThread = NULL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ GLOBAL::WriteTextLog(_T("结束标准输出日志线程失败"));
|
|
|
}
|
|
|
-
|
|
|
- CloseHandle(m_hStdoutLogThread);
|
|
|
- m_hStdoutLogThread = NULL;
|
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
if ( m_hStderrLogThread ) {
|
|
|
- if ( WaitForSingleObject(m_hStderrLogThread, 3000) == WAIT_OBJECT_0 ) {
|
|
|
+ if ( WaitForSingleObject(m_hStderrLogThread, 5000) == WAIT_OBJECT_0 ) {
|
|
|
CloseHandle(m_hStderrLogThread);
|
|
|
m_hStderrLogThread = NULL;
|
|
|
}
|
|
@@ -458,14 +461,16 @@ void CPythonExecutor::EndLogThread()
|
|
|
|
|
|
// 手动结束线程;
|
|
|
if (m_hStderrLogThread) {
|
|
|
- // 尝试5次结束行为;
|
|
|
- for (int i = 0; i < 5; i++) {
|
|
|
- if (TerminateThread(m_hStderrLogThread, 0))
|
|
|
- break;
|
|
|
+ TerminateThread(m_hStderrLogThread, 0);
|
|
|
+ // 异步结束,需要等待(5秒)系统完成操作;
|
|
|
+ if ( WaitForSingleObject(m_hStderrLogThread, 5000) == WAIT_OBJECT_0 ) {
|
|
|
+ CloseHandle(m_hStderrLogThread);
|
|
|
+ m_hStderrLogThread = NULL;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ GLOBAL::WriteTextLog(_T("结束标准错误日志线程失败"));
|
|
|
}
|
|
|
-
|
|
|
- CloseHandle(m_hStderrLogThread);
|
|
|
- m_hStderrLogThread = NULL;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -477,16 +482,16 @@ void CPythonExecutor::EndThread()
|
|
|
|
|
|
BOOL CPythonExecutor::EndSubprocess()
|
|
|
{
|
|
|
- BOOL ret = false;
|
|
|
- if (m_pi.hProcess) {
|
|
|
- // 尝试5次结束;
|
|
|
- for (int i = 0; i < 5; i++) {
|
|
|
- if ( (ret = TerminateProcess(m_pi.hProcess, 0)) )
|
|
|
- break;
|
|
|
- }
|
|
|
+ // 注意TerminateProcess是异步的;
|
|
|
+ TerminateProcess(m_pi.hProcess, 0);
|
|
|
+ // 异步结束,需要等待(5秒)系统完成操作;
|
|
|
+ if ( WaitForSingleObject(m_pi.hProcess, 5000) == WAIT_OBJECT_0 ) {
|
|
|
+ GLOBAL::WriteTextLog(_T("结束进程(%ld)成功"), m_pi.dwProcessId);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
- return ret;
|
|
|
+ GLOBAL::WriteTextLog(_T("结束进程(%ld)失败"), m_pi.dwProcessId);
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
void CPythonExecutor::EndSubprocessStdOut()
|
|
@@ -598,7 +603,5 @@ bool CPythonExecutor::IsScriptOver()
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- //GLOBAL::WriteTextLog(_T("====>脚本(%s)未结束"), m_pCaseObj->strCaseName.c_str());
|
|
|
-
|
|
|
return false;
|
|
|
}
|