通过IDE和命令提示符运行代码时,Python线程行为不同

时间:2013-07-29 21:59:19

标签: python windows multithreading selenium command-line

我在自动化网页时遇到了问题,我找到了here的解决方案。 在我的回答中,第二个代码片段是

#Assume that at this point you are on the page where you need to click on a Web Element to      trigger native OS window/dialog box

def _action_on_trigger_element(_element):
    _element.click()

trigger_element = driver.find_element_by_id('ID of the Web Element which triggers the window')
th = threading.Thread(target = _action_on_trigger_element, args = [trigger_element])  #Thread is    created here to call private func to click on Save button
th.start()                          #Thread starts execution here
time.sleep(1)                       #Simple Thread Synchronization handle this case.          

#Call WindowFinder Class
win = WindowFinder()
win.find_window_wildcard(".*Save As.*") 
win.set_foreground()
path = "D:\\File.txt"            #Path of the file you want to Save 
ent = "{ENTER}"                  #Enter key stroke.
SendKeys.SendKeys(path)          #Use SendKeys to send path string to Save As dialog
SendKeys.SendKeys(ent)           #Use SendKeys to send ENTER key stroke to Save As dialog

#At this point the native OS window is interacted with and closed after passing a key stroke ENTER.
# Go forward with what ever your Automation code is doing after this point

当我从IDE Aptana Studio3运行代码时,代码运行正常并且我的线程调用私有函数_action_on_trigger_element(_element)但是当我通过命令行运行相同的代码时调用Python脚本线程不会调用作为其目标的函数。

我检查了线程是否还活着。对此和解决方法的任何解释都表示赞赏。

由于

0 个答案:

没有答案