YueChen-C / py-ios-device

IOS Professional Performance Testing Tool . You can get CPU, GPU, Memory , Lifecycle and other metrics from real iOS devices . IOS 专业性能测试工具
GNU General Public License v3.0
633 stars 179 forks source link

ios17 截图不太稳定 经常提示报错 #139

Closed hyfand closed 2 months ago

hyfand commented 2 months ago
import time
from ios_device.servers.dvt import DTXServer
from ios_device.remote.remote_lockdown import RemoteLockdownClient
from ios_device.servers.Instrument import InstrumentServer
from ios_device.util.variables import InstrumentsService
host = 'fd88:806d:8f61::1'
port = 61810

with RemoteLockdownClient((host, port)) as rsd:
    rpc = InstrumentServer(rsd).init()
    data = rpc.call(InstrumentsService.Screenshot, "takeScreenshot").selector
    print("start.")
    print(data)
    print("ending.")

以下是报错信息:

Traceback (most recent call last):
  File "/Users/happyelements/PycharmProjects/test_use/ios17_test/test03.py", line 15, in <module>
    data = rpc.call(InstrumentsService.Screenshot, "takeScreenshot").selector
  File "/Users/happyelements/PycharmProjects/test_use/venv/lib/python3.9/site-packages/ios_device/servers/dvt.py", line 185, in call
    channel_id = self.make_channel(channel)
  File "/Users/happyelements/PycharmProjects/test_use/venv/lib/python3.9/site-packages/ios_device/servers/dvt.py", line 180, in make_channel
    self._call(True, 0, "_requestChannelWithCode:identifier:", channel_id, channel)
  File "/Users/happyelements/PycharmProjects/test_use/venv/lib/python3.9/site-packages/ios_device/servers/dvt.py", line 223, in _call
    self._client.send_dtx(self._cli, dtx)
  File "/Users/happyelements/PycharmProjects/test_use/venv/lib/python3.9/site-packages/ios_device/servers/dvt.py", line 38, in send_dtx
    return client.send(buffer)
AttributeError: 'NoneType' object has no attribute 'send'

重试多次都不行,提示cli是None

YueChen-C commented 2 months ago

没遇到啊,什么场景型号和环境?

hyfand commented 2 months ago

是这样的, 我开了一个rpc连接,然后一直复用这个连接请求图,然后时间一长就会提示 AttributeError: 'NoneType' object has no attribute 'send'

具体代码如下

def iter_screenshot(rsd: object, udid: object) -> object:

    channel = InstrumentsService.Screenshot
    rpc = InstrumentServer(rsd, udid).init()
    while True:
        try:
            data = rpc.call(channel, "takeScreenshot").selector
            time.sleep(3)
            if data:
                rpc.stop()
        except Exception:
            traceback.print_exc()
            print("[截图]rpc 连接失败, 将重新连接")
            time.sleep(3)
            continue
        memory_fd = io.BytesIO(data)
        im = Image.open(memory_fd)
        im.load()
        del (memory_fd)
        yield im

貌似会断连接,不知道原因。 现在处理是每次开一个新rpc去请求一张截图,然后关掉rpc,这样的处理的。 您知道代码问题所在 或者 为什么会断连接丢失 cli 为 None 吗。

YueChen-C commented 2 months ago

windows 吗 windows 的话图片比较大,好像堵塞然后早成 socket 断开。

hyfand commented 2 months ago

问题发生在mac电脑。 windows上次我提过了,您说通道阻塞,我已暂时放弃windows平台截图。 感谢作者, 我已经解决,每次建立新连接,拿到图就断开。

YueChen-C commented 2 months ago

mac 我试了循环 5 分钟没出现你所说问题 ,业务层解决也行出现错误再重启一个实例。