python:futures线程实现return返回值

一、依赖库:

import concurrent.futures

二、代码

import concurrent.futures
import time
import can
import os


def can_recv():
    channel = 0
    can_id = 0x531
    message = '00000C0000000000|6'
    vector_bus = can.interface.Bus(interface='vector', app_name=None, channel=channel, bitrate=500000)
    vector_bus.set_filters([{"can_id": can_id, "can_mask": 0xFFFF, "extended": False}])
    start_time = time.time()
    list_all = []
    while True:
        msg = vector_bus.recv(0.001)
        if msg is not None:
            list_all.append(msg.data.hex())
        end_time = time.time()
        if int(end_time - start_time) >= 3:
            # print(list_all)
            break
    vector_bus.shutdown()

    passNUM = 0
    Byte_bit = int(message.split("|")[1]) - 1
    exp_msg_date = message.split("|")[0]
    exp_msg_date_bite = exp_msg_date[Byte_bit]

    for i in range(0, len(list_all)):
        act_msg_data = str(list_all[i])
        print(act_msg_data)
        act_msg_date_bite = act_msg_data[Byte_bit]
        if act_msg_date_bite == exp_msg_date_bite:
            passNUM += 1
    return passNUM


def click_axis(coordinate):
    os.system('adb shell input tap {}'.format(coordinate))


if __name__ == '__main__':
    coordinate = '1845 670'
    executor = concurrent.futures.ThreadPoolExecutor()
    future = executor.submit(can_recv)
    click_axis(coordinate)
    time.sleep(3)
    result = future.result()
    assert result == 3

三、使用场景

车机点击按钮外发三帧报文时,需要提前开始接收报文

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值