Python pyuv进程执行函数而不是文件
我正在开发一个应用程序,其中包括复制潜在的大文件,以响应某些UDP请求。我使用pyuv来侦听和处理这些请求,并希望生成一个单独的进程来完成这些复制操作,这样我的主循环就不会被阻塞 目前,我以以下方式使用python的多处理和pyuv库Python pyuv进程执行函数而不是文件,python,multiprocessing,python-multiprocessing,libuv,Python,Multiprocessing,Python Multiprocessing,Libuv,我正在开发一个应用程序,其中包括复制潜在的大文件,以响应某些UDP请求。我使用pyuv来侦听和处理这些请求,并希望生成一个单独的进程来完成这些复制操作,这样我的主循环就不会被阻塞 目前,我以以下方式使用python的多处理和pyuv库 # Get read and write pipes from the OS r, w = os.pipe() # Construct pyuv reading pipe and assign callback pipe_read = pyuv.Pipe(sel
# Get read and write pipes from the OS
r, w = os.pipe()
# Construct pyuv reading pipe and assign callback
pipe_read = pyuv.Pipe(self.loop)
pipe_read.open(r)
pipe_read.start_read(self.read_pipe)
# Construct pyuv writing pipe
pipe_write = pyuv.Pipe(self.loop)
pipe_write.open(w)
# Keep track of pending file operations associated with the read_pipe fileno()
# Allows us to correctly close both pipes
self.pending[pipe_read.fileno()] = (msg.refDataID, msg.refDataSubID, pipe_read, pipe_write, msg.lastEventTime)
# Spawn off a process to operate on the files and write to the pipe
p = Process(target=self.perform_action, args=(pipe_write, src, dest, ))
p.start()
其中self.perform\u操作如下所示:
def perform_action(self, pipe, src, dest):
ret_val = self.copy_function(src, dest)
pipe.write(str(ret_val) # Write the return value to the pipe - triggers the read_pipe callback
我使用管道来获取返回值,这也是因为我希望在进程完成管道读取时触发回调。start\u readself.read\u pipe在向管道写入内容时分配回调
我很想用pyuv.Process模块来代替上面提到的内容,但是我似乎找不到任何文档或示例来让程序以函数而不是文件为目标。当我的进程完成时,使用管道触发回调并返回ret_val,感觉有些不对劲,如果我能让pyuv.process工作并只使用它的callbackprocess_句柄、exit_status、term_信号回调,那就太好了
有什么想法吗?这似乎是可能的吗?pyuv作者:这是不可能的,libuv的uv_spawn函数将自己创建一个新进程。但是,您可以将处理函数放在另一个python文件中,然后生成该文件。谢谢您的响应!这不完全是我要找的,但我能做得到。