Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

每创建一个 Driver(serial) 对象,就会创建一次 socket 连接,这个Driver对象是不是需要复用? #14

Open
smuyyh opened this issue Nov 4, 2024 · 4 comments

Comments

@smuyyh
Copy link

smuyyh commented Nov 4, 2024

No description provided.

@smuyyh
Copy link
Author

smuyyh commented Nov 4, 2024

如果不复用的话,建立的 socket 连接,假设有个 Driver 关闭连接,关闭端口转发,就会影响到其他对象..

@smuyyh
Copy link
Author

smuyyh commented Nov 4, 2024

但实际情况是,多个地方大概率会 通过 serial 去创建 Driver,那就相互影响了

@smuyyh
Copy link
Author

smuyyh commented Nov 4, 2024

看起来只适用于单线程模型,多线程下,就算 Driver 复用,例如录屏过程中,随便调用一下 d.device_info() 之类的,接收消息就会被打乱

@codematrixer
Copy link
Owner

  1. dirver是一个单例模式,相同serial的driver不会重复创建
    def __new__(cls: Type[Any], serial: str) -> Any:
        """
        Ensure that only one instance of Driver exists per device serial number.
        """
        if serial not in cls._instance:
            cls._instance[serial] = super().__new__(cls)
        return cls._instance[serial]
  1. 单台设备自动化的场景本来就是单线程的,同时操作一台手机,UI序列也会乱掉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants