多处理python的行为不符合预期

2024-04-19 10:18:22 发布

您现在位置:Python中文网/ 问答频道 /正文

您好,我正在使用多处理库从main()运行两个不同的函数:

Coap = multiprocessing.Process(target=runCoapSync(iotComponent))
huis=multiprocessing.Process(target=runHuis(iotComponent))
huis.start()
Coap.start()

问题是函数runHuis()没有被触发,但是如果我为运行另一个函数添加了注释行,函数runHuis()就会按预期工作。我在代码的其他地方使用了完全相同的结构,但它工作得很好

以下是两个函数的代码:

def runHuis(iotDevice):
    print("----------------1---------------")
    LCD=iotDevice.connectedHUIs[0]
    while True:
        LCD.alertHuman(iotDevice.connectedSensors[0].data.value)

def runCoapSync(iotDevice):
    print("----------------2---------------")
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop.run_until_complete(runCoap(iotDevice))

Tags: 函数代码looptargetdefmultiprocessingprocessstart