首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >管道堵塞功能

管道堵塞功能
EN

Stack Overflow用户
提问于 2022-08-11 11:06:54
回答 1查看 36关注 0票数 0

最近,我一直在工作的管道和覆盆子皮。我正试图向我的函数发送一个信号来杀死它,但是"pipe.recv“阻塞了这个函数。信号是发送的,但是while循环没有被执行。

代码语言:javascript
复制
from multiprocessing import Process, Pipe
import time
import os
import signal

def start(pipe):
    pipe1 = pipe[1].recv()
    while True:
       print('hello world')
    os.kill(pipe1,signal.SIGTERM)
if __name__ == "__main__":
    conn1 = Pipe()
    a = Process(target = start,args = (conn1,))
    a.start()
    time.sleep(5)
    print("TIMES UP")
    conn1[1].send(a.pid)
EN

回答 1

Stack Overflow用户

发布于 2022-08-11 11:44:40

您正在发送,并试图从管道的同一端检索该项。尝试这样做,在这里,pipe[0]pipe[1]被命名为parentchild,以提高可读性:

代码语言:javascript
复制
from multiprocessing import Process, Pipe
import time
import os
import signal

def start(child):
    pipe1 = child.recv()
    while True:
       print('hello world')
    os.kill(pipe1,signal.SIGTERM)
if __name__ == "__main__":
    parent, child = Pipe()
    a = Process(target = start,args = (child,))
    a.start()
    time.sleep(5)
    print("TIMES UP")
    parent.send(a.pid)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73319634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档