Python中的错误选取错误

时间:2016-08-13 06:08:44

标签: python pickle

我目前正在研究一种在命名管道之间传输数据的系统。当我尝试设置一个监听器来阅读它时,我得到一个奇怪的错误。仅当我将多条消息传递到管道中时才会出现此错误。

这是我得到的错误:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "/home/learn_pipes.py", line 96, in extract_from_pipe
    message = pickle.load(pipe_rd)
_pickle.UnpicklingError: bad pickle data

这是我的接收方式:

def extract_from_pipe(self):
    with open(path, "rb") as pipe_rd:
        while True:
            try:
                if(os.path.getsize(path) > 0):
                    print(path)
                    message = pickle.load(pipe_rd)
                    print(message)
                    with self.arrived_condition:
                        self.communication_queue.put(message)
                        self.arrived_condition.notify()
            except EOFError:
                time.sleep(0.01)

这就是我选择数据的方式:

def send(self, pid, *values): #Works
    with open(path, "wb") as pipe:
       pickle.dump(values, pipe)

for num in range(1000):
    me.send(consumer, 'message', num + 1)

任何想法可能是什么问题?当我只传递一个send实例时,我不确定为什么这是糟糕的pickle数据?

0 个答案:

没有答案