1

I have a very simple queue which is used between Python3 modules in Raspberry Pi. I want to send messages to the same queue from one Python2 module. Does not work.

Server is running in Python3 as in this example:

from multiprocessing.managers import BaseManager
import Queue
queue = Queue.Queue()
class QueueManager(BaseManager): pass
QueueManager.register('get_queue', callable=lambda:queue)
m = QueueManager(address=('', 50000), authkey='abracadabra')
s = m.get_server()
s.serve_forever()

Sender is like this:

from multiprocessing.managers import BaseManager
class QueueManager(BaseManager): pass
QueueManager.register('get_queue')
m = QueueManager(address=('foo.bar.org', 50000), authkey='abracadabra')
m.connect()
queue = m.get_queue()
queue.put('hello')

With both only in Python3 or in Python2 everything runs perfectly. If server is in Python3 and sender is in Python2, result is the following error:

Blockquote

Traceback (most recent call last): File "sender_V2.py", line 22, in m.connect() File "/usr/lib/python2.7/multiprocessing/managers.py", line 501, in connect >dispatch(conn, None, 'dummy') File "/usr/lib/python2.7/multiprocessing/managers.py", line 102, in dispatch >kind, result = c.recv() ValueError: unsupported pickle protocol: 3

Community
  • 1
  • 1
  • 2
    Python 2 can't deserialise data pickled by Python 3 using the latest protocol, see e.g. https://docs.python.org/3/library/pickle.html#data-stream-format. There's a workaround [here](https://stackoverflow.com/a/7922877/3001761), but you might be better using a proper external queue where you can control the serialisation format. See also https://stackoverflow.com/q/54135972/3001761 – jonrsharpe Jan 20 '19 at 15:30
  • It might be easier to just use language agnostic MQ like ZeroMQ, Protobufs, or even just simple JSON over UDP. – Gillespie Jan 20 '19 at 18:54
  • Unfortunately changing the existing solution to something new is too much work. It is surprising that compatibility mode between between Python 2 and Python 3 is not available. Should not be too difficult, because the same code using queue works exactly the same way in both pythons. Naturally with the known syntax changes. – Juhani Miettunen Jan 21 '19 at 06:55
  • This is the easiest way to go: https://stackoverflow.com/questions/27863832/calling-python-2-script-from-python-3 – Juhani Miettunen Jan 22 '19 at 10:36

0 Answers0