AirtestProject / AirtestProject/Airtest

使用multiprocessing报错,AttributeError: 'NoneType' object has no attribute 'snapshot'

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

Mô tả

## 需求:
一边执行基本的识别点击操作(main_operation()),一边检测有没有对应的其他图片出现在界面中(sub_operation()),所以使用multiprocessing来处理。

## 问题:
不使用multiprocessing只执行上述一个操作时正常,但使用multiprocessing之后,哪怕只执行(main_operation())也会出现如下错误
```
Process Process-1:
Traceback (most recent call last):
File "C:\Users\a\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\process.py", line 314, in _bootstrap
self.run()
File "C:\Users\a\AppData\Local\Programs\Python\Python311\Lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "H:\code\python3\python\QuickTools\AirtestTest.py", line 238, in main_operation
all_pos = find_all(Template(r"resource/safe_state.PNG"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\a\AppData\Local\Programs\Python\Python311\Lib\site-packages\airtest\utils\logwraper.py", line 122, in wrapper
res = f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File "C:\Users\a\AppData\Local\Programs\Python\Python311\Lib\site-packages\airtest\core\api.py", line 655, in find_all
screen = G.DEVICE.snapshot(quality=ST.SNAPSHOT_QUALITY)
^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'snapshot'
```

## 我的代码
```
def main_operation():
print('main_operation')
all_pos = find_all(Template(r"resource/safe_state.PNG"))
print(all_pos)

def main():
t1 = Process(target=main_operation)
# t2 = Process(target=sub_operation)
t1.start()
# t2.start()
t1.join()
# t2.join()
```

### 请教下如何解决该问题,谢谢!

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.