推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Nepheshel
V2EX  ›  Python

qthread 如何暂停进程 等待 ui 界面输入参数 点击按钮 继续进程 试了几个方法都是直接卡死

  •  1
     
  •   Nepheshel · Jun 26, 2018 · 2826 views
    This topic created in 2890 days ago, the information mentioned may be changed or developed.
    Supplement 1  ·  Jun 27, 2018
    程序是截屏裁剪验证码 然后传到 UI 界面 手动输入后 登陆网站
    所以需要在手动输入时 程序暂停 输入完毕 继续进程
    现在的情况是暂停就卡死了 有注意到一点 暂停部分如果用 time.sleep 验证码、文本会在 sleep 结束了以后才在 UI 呈现出来 等待期间 ui 是假死状态的
    感觉上是这个原因 暂停完 UI 就假死状态 点了就崩溃 不知道怎么办
    while True:
    #获取验证码图片
    driver.save_screenshot("auth_code.png")
    im = Image.open("auth_code.png")
    (x,y,w,h) = (930,300,95,40)
    im_cut = im.crop((x, y, x+w, y+h))
    im_cut.save("auth_code_cut.png")
    png = QtGui.QPixmap('C:/Temp/PythonAnalyse/auth_code_cut.png')
    ui.label_3.setPixmap(png)
    #手动输入验证码
    ui.label_2.setText('请输入验证码')
    #暂停
    #time.sleep(10)
    cond.wait()
    driver.find_element_by_xpath('//*[@id=\'uc-login\']/div/div[3]/input').send_keys(authCode)
    #点击登陆
    driver.find_element_by_xpath('//*[@id=\'uc-login\']/div[2]/input').click()
    time.sleep(1)
    4 replies    2018-06-27 17:55:58 +08:00
    weyou
        1
    weyou  
       Jun 26, 2018
    点击暂停按钮触发一个“ pause event ”,在 thread 里一边 do your things,一边循环 check 这个 event,如果发现“ pause event ”被触发, 进入单独的等待循环持续 check 这个“ pause event ”是否被 reset, 这时如果用户点击”继续“按钮 reset 前面的” pause event “, 将前面的等待循环解除, 这时候就 qthread 能继续做事情了。

    不过如果参数比较少,可以用线程同步的方式实时传到线程里,不需要暂停。
    cyrbuzz
        2
    cyrbuzz  
       Jun 26, 2018
    用信号呀,自定义信号,点了按钮后发出这个信号,接收到信号后启动 /恢复线程。
    Tyanboot
        3
    Tyanboot  
    PRO
       Jun 26, 2018 via Android
    用 condition_variable 锁上?点击按钮再用 notify 恢复。
    Nepheshel
        4
    Nepheshel  
    OP
       Jun 27, 2018
    感谢各位的回答 问题解决了 原因是 我的线程表达式写错了 没能跟 UI 分离出来
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   952 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 56ms · UTC 19:46 · PVG 03:46 · LAX 12:46 · JFK 15:46
    ♥ Do have faith in what you're doing.