AirtestProject / AirtestProject/Poco

poco经常卡死在某个方法里

Đang mở
#286 4 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
2k
Fork
341
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

(请尽量按照下面提示内容填写,有助于我们快速定位和解决问题,感谢配合。否则直接关闭。)
多线程执行poco一系列操作,比如poco.exists()等,在操作poco时已加上锁(以前未加锁也经常出现,现在加了锁还是会出现,只是概率少了)
已排除以下因素:
1,手机问题,用了多台手机测试,均会出现,应该与手机无关
2,系统问题,在win7.64,树莓派,ubuntu16.64系统都会出现

**描述问题bug**

```
# 以下为测试代码 ===>>>

#!/usr/bin/python3
# coding: utf-8

import logging, os, sys
sys.path.append(os.path.dirname(__file__))

from airtest.core.api import *
import random, time, threading
from airtest.core.api import *
from airtest.core.android.android import Android

from poco.drivers.android.uiautomation import AndroidUiautomationPoco

package_name = 'com.planet.light2345'
poco = None
devicex = None
logger = None

lock = threading.Lock()

def run():
global devicex, poco, logger
logger = init_logger('test')

devicex = connect_device('android:///')

logger.info(devicex)

poco = AndroidUiautomationPoco(devicex, use_airtest_input=True, screenshot_each_action=False)
auto_setup(__file__)

_run()

def init_logger(device_id):
logger = logging.getLogger(device_id)
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
formatter = logging.Formatter(
fmt='[%(asctime)s][%(levelname)s][%(filename)s:%(lineno)d] %(message)s',
datefmt='%Y-%m-%d %I:%M:%S'
)
handler.setFormatter(formatter)
logger.addHandler(handler)

return logger

def _run():
t = threading.Thread(target=_thread)
t.setDaemon(True)
t.start()

sleep(3)

_main()

def _thread():
logger.info('_thread start')
c = 0
while True:
logger.info('_thread..... %s 1 ***', c)
lock.acquire()
logger.info('_thread..... %s 2 ***', c)
poco('hehehexfee').exists()
logger.info('_thread..... %s 3 ***', c)
keyevent('BACK')
logger.info('_thread..... %s 5 ***', c)
lock.release()
logger.info('_thread..... %s 6 ***', c)

sleep(0.04)
c += 1

logger.info('_thread..... <<<<<<--------------------')

def _main():
logger.info('_main start')
c = 0
while True:
logger.info('_main....=>> 1 %s--', c)
lock.acquire()
logger.info('_main....=>> 2 %s--', c)
poco('(47209502309nbek').exists()
logger.info('_main....=>> 4 %s--', c)
poco.swipe([0.4, 0.2], [0.46, 0.58], duration=0.3)
logger.info('_main....=>> 5 %s--', c)
lock.release()
logger.info('_main....=>> 7 %s--', c)

sleep(0.08)
c += 1

logger.info('_main (((==============..........')

if __name__ in ['__main__', 'airtest.cli.runner']:
run()

```

```
# 以下为log,以及ctrl+C后的信息
[2019-09-03 05:29:58][INFO][mmx.py:82] _main....=>> 1 354--
[2019-09-03 05:29:59][INFO][mmx.py:67] _thread..... 357 5 ***
[2019-09-03 05:29:59][INFO][mmx.py:69] _thread..... 357 6 ***
[2019-09-03 05:29:59][INFO][mmx.py:84] _main....=>> 2 354--
[2019-09-03 05:29:59][INFO][mmx.py:61] _thread..... 358 1 ***
[2019-09-03 05:29:59][INFO][mmx.py:86] _main....=>> 4 354--
[2019-09-03 05:30:00][INFO][mmx.py:88] _main....=>> 5 354--
[2019-09-03 05:30:00][INFO][mmx.py:90] _main....=>> 7 354--
[2019-09-03 05:30:00][INFO][mmx.py:63] _thread..... 358 2 ***
[2019-09-03 05:30:00][INFO][mmx.py:82] _main....=>> 1 355--

# 到这一步,程序已卡死,没有再执行下去,以下为 Ctrl+C后的报错信息

^CTraceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 380, in _make_request
[pocoservice.apk] stdout: b'\ncom.netease.open.pocoservice.InstrumentedTestAsLauncher:'
[pocoservice.apk] stderr: b''
httplib_response = conn.getresponse(buffering=True)
TypeError: getresponse() got an unexpected keyword argument 'buffering'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.6/dist-packages/airtest/__main__.py", line 6, in
main()
File "/usr/local/lib/python3.6/dist-packages/airtest/cli/__main__.py", line 16, in main
run_script(args)
File "/usr/local/lib/python3.6/dist-packages/airtest/cli/runner.py", line 138, in run_script
result = unittest.TextTestRunner(verbosity=0).run(suite)
File "/usr/lib/python3.6/unittest/runner.py", line 176, in run
test(result)
File "/usr/lib/python3.6/unittest/suite.py", line 84, in __call__
return self.run(*args, **kwds)
File "/usr/lib/python3.6/unittest/suite.py", line 122, in run
test(result)
File "/usr/lib/python3.6/unittest/case.py", line 653, in __call__
return self.run(*args, **kwds)
File "/usr/lib/python3.6/unittest/case.py", line 605, in run
testMethod()
File "/usr/local/lib/python3.6/dist-packages/airtest/cli/runner.py", line 61, in runTest
exec(compile(code.encode("utf-8"), pyfilepath, 'exec'), self.scope)
File "/home/yang/mmx.py", line 109, in
run()
File "/home/yang/mmx.py", line 37, in run
_run()
File "/home/yang/mmx.py", line 60, in _run
_main()
File "/home/yang/mmx.py", line 92, in _main
poco('(47209502309nbek').exists()
File "/usr/local/lib/python3.6/dist-packages/poco/proxy.py", line 72, in wrapped
return func(proxy, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/poco/proxy.py", line 774, in exists
return self.attr('visible')
File "/usr/local/lib/python3.6/dist-packages/poco/proxy.py", line 39, in wrapped
return func(self, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/poco/proxy.py", line 734, in attr
nodes = self._do_query(multiple=False)
File "/usr/local/lib/python3.6/dist-packages/poco/proxy.py", line 872, in _do_query
self._nodes = self.poco.agent.hierarchy.select(self.query, multiple)
File "/usr/local/lib/python3.6/dist-packages/poco/utils/retry.py", line 15, in wrapped
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/poco/utils/hrpc/hierarchy.py", line 33, in select
return self.selector.select(query, multiple)
File "/usr/local/lib/python3.6/dist-packages/hrpc/object_proxy.py", line 92, in __call__
return self._client__.evaluate(self.__call_no_evaluate__(remote_obj_cache, *args))
File "/usr/local/lib/python3.6/dist-packages/hrpc/client.py", line 63, in evaluate
self.transport.send({'id': reqid, 'uri': obj_proxy._uri__, 'method': obj_proxy._invocation_path__})
File "/usr/local/lib/python3.6/dist-packages/hrpc/transport/http.py", line 23, in send
r = requests.post(self.endpoint, data=json.dumps(req), headers={'Content-Type': 'application/json'})
File "/usr/lib/python3/dist-packages/requests/api.py", line 112, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/lib/python3/dist-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 520, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 630, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 440, in send
timeout=timeout
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 601, in urlopen
chunked=chunked)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 383, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.6/http/client.py", line 1331, in getresponse
response.begin()
File "/usr/lib/python3.6/http/client.py", line 297, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.6/http/client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.6/socket.py", line 586, in readinto
return self._sock.recv_into(b)
KeyboardInterrupt
[03:16:23][DEBUG] /usr/local/lib/python3.6/dist-packages/airtest/core/android/static/adb/linux/adb -s 721QACRG644X7 forward --remove tcp:14405
[03:16:23][DEBUG] /usr/local/lib/python3.6/dist-packages/airtest/core/android/static/adb/linux/adb -s 721QACRG644X7 forward --remove tcp:18106
[03:16:23][DEBUG] /usr/local/lib/python3.6/dist-packages/airtest/core/android/static/adb/linux/adb -s 721QACRG644X7 forward --remove tcp:13054

```

**执行脚本命令:** `python3 -m airtest run mmx.py`
**python 版本:** `Python 3.6.7`

**airtest 版本:** `airtest==1.0.27`
> airtest版本通过`pip freeze`可以命令可以查到

**其他相关环境信息**
在win7.64,树莓派,ubuntu16.64系统都会出现卡死现象

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.