leng-yue / py-scrcpy-client

An easy to use python scrcpy client
https://leng-yue.github.io/py-scrcpy-client/
MIT License
283 stars 71 forks source link

threaded=True时assert这句会报错吧 #21

Closed erichuang1995 closed 2 years ago

erichuang1995 commented 2 years ago

https://github.com/leng-yue/py-scrcpy-client/blob/4ae9b2d57dfb9ac4a179316048cfdf74b7e6e8e1/scrcpy/core.py#L152

这里这样写,当threaded=True时,那assert self.alive is False不就永远都异常了吗?

def main(max_width: int, device: Optional[str]):
    m = MainWindow(max_width, device)
    m.show()
    m.client.start(threaded=True)
    while m.alive:
        m.client.start(threaded=True)
leng-yue commented 2 years ago

m.alive 是用来判断是否用户手动停止的, 和 m.client.alive 不是同一个变量.

如果启用了 threaded=True, 这块就会抛出异常了, 因为在用户不手动停止的情况下 m.alive 恒等于 true.

如果你希望在使用线程的情况下等待上一次连接断开, 可以尝试:

def main(max_width: int, device: Optional[str]):
    m = MainWindow(max_width, device)
    m.show()
    m.client.start(threaded=True)
    while m.alive:
        time.sleep(1)
        if m.client.alive is False:
            m.client.start(threaded=True)