referral_pinggu.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:referral_pinggu 作者: XiangwenWang 项目源码 文件源码
def __call__(self, *args, **kargs):

        def function_process(pipe, function, args, kargs):
            pipe.send(function(*args, **kargs))  # A: result got from function process

        p_pipe, c_pipe = multiprocessing.Pipe()
        p = Process(target=function_process, args=(c_pipe, self.function, args, kargs))
        p.start()
        p.join(self._timeout_threshold)  # Wait

        if p.exception:
            # if there is other Error
            raise RuntimeError
        elif p.is_alive():
            # if passes the timeout threshold, terminate function process
            p.terminate()
            raise TimeoutError('Timeout')
        else:
            return p_pipe.recv()  # return result from A
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号