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
  • 4
    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
  • 1
    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

1 Answers1

0

See this Github link

I used REDIS (with the server running on Ubuntu under Windows WSL) and I was able to pass a Pandas DataFrame from a Py2 miniconda shell to a Py3 miniconda shell running different scripts. The Py2 was running hardware where the company had not upgraded drivers and such to Py3. But the GUI and UX were best done in Py3. REDIS is pretty cool but it was kind of tricky since Py2 needed to use the BytesIO instead of StringIO wrapper that would normally work in Py3.

Joab.Ai
  • 13
  • 3
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 15 '23 at 20:27
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/33633310) – Aero Blue Jan 19 '23 at 21:07