$ sudo pip install posix_ipc
#!/usr/local/env python
# -*- coding: utf-8 -*-
import json
import posix_ipc
import time
if __name__ == "__main__":
posix_ipc.unlink_message_queue("/queue_name")
mq = posix_ipc.MessageQueue("/queue_name", posix_ipc.O_CREX)
counter = 0
while True:
counter += 1
#Enqueue with send, str,Send unicode
mq.send(json.dumps({"loop_count": counter}))
print "queue: %d" % counter
time.sleep(1.0)
posix_ipc.unlink_message_queue("/queue_name")
#!/usr/local/env python
# -*- coding: utf-8 -*-
import json
import posix_ipc
import time
if __name__ == "__main__":
mq = posix_ipc.MessageQueue("/queue_name")
while True:
msg = mq.receive()
print json.loads(msg[0])
time.sleep(0.5)
Recommended Posts