有什么方法可以在Python中的多个过程之间传递过程对象?
我在同一目录中有两个文件, 一个模块具有持续运行的函数,无法停止或暂停之间,
# script.py
def run():
i = 0
while True:
print('\r', i, '\r', end='')
i += 1
然后有一个自定义的调试器模块,如果目录已更新,
# debugger.py
import os
import wait
from multiprocessing import Process, Queue
def capture_change(processesQueue):
prev = os.path.getsize('wait.py')
while True:
curr = os.path.getsize('wait.py')
if curr != prev:
print('Changes Detected!!')
process = processesQueue.get()
process.kill()
process.start()
processesQueue.put(process)
prev = curr
if __name__ == "__main__":
processesQueue = Queue()
p1 = Process(target= wait.run)
processesQueue.put(p1)
p2 = Process(target= capture_change, args= (processesQueue, ))
p1.start()
p2.start()
我会捕获此错误,
raise TypeError(
TypeError: Pickling an AuthenticationString object is disallowed for security reasons
我该怎么办? 我已经搜索了很多,但是在其他过程中进行数据共享的所有方法都不允许在其中共享过程实例本身。还有其他方法吗?
I have two files in the same directory,
A module has a function that is continously running and has no way to stop or pause in between,
# script.py
def run():
i = 0
while True:
print('\r', i, '\r', end='')
i += 1
Then there is a custom made debugger module which captures if the directory has been updated,
# debugger.py
import os
import wait
from multiprocessing import Process, Queue
def capture_change(processesQueue):
prev = os.path.getsize('wait.py')
while True:
curr = os.path.getsize('wait.py')
if curr != prev:
print('Changes Detected!!')
process = processesQueue.get()
process.kill()
process.start()
processesQueue.put(process)
prev = curr
if __name__ == "__main__":
processesQueue = Queue()
p1 = Process(target= wait.run)
processesQueue.put(p1)
p2 = Process(target= capture_change, args= (processesQueue, ))
p1.start()
p2.start()
I am getting this error,
raise TypeError(
TypeError: Pickling an AuthenticationString object is disallowed for security reasons
What should I do?
I have searched alot but all the ways for data sharing among other processes are not allowing Process instance itself to be shared among them. Is there any other way around??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
多亏了@flakes,我终于在希望达到的部分方面得到了解决,
这是我的最终代码,可根据需要运行。
Thanks to @flakes I have finally got a way around the part I was hoping to achieve,
This is my final code that works as required.