mood.mqueue

Python POSIX message queues interface (Linux only)


Keywords
linux, mqueue, mood
License
GPL-3.0
Install
pip install mood.mqueue==1.0.1

Documentation

mood.mqueue

Python POSIX message queues interface (Linux only)

POSIX message queues allow processes to exchange data in the form of messages.

See also: mq_overview - overview of POSIX message queues


MessageQueue(name, flags[, mode=0o600, maxmsg=-1, msgsize=-1])
  • name (str)

    Each message queue is identified by a name of the form /somename; that is, a string consisting of an initial slash, followed by one or more characters, none of which are slashes. Two processes can operate on the same queue by passing the same name.

  • flags (int)

    Exactly one of the following must be specified in flags:

    • O_RDONLY
      Open the queue to receive messages only.
    • O_WRONLY
      Open the queue to send messages only.
    • O_RDWR
      Open the queue to both send and receive messages.

    Zero or more of the following flags can additionally be ORed in flags:

    If O_CREAT is specified in flags, then three additional optional arguments can be supplied:

    • mode (int: 0o600)
      The mode argument specifies the permissions to be placed on the new queue. The permissions settings are masked against the process umask. mode may take one of the following values or bitwise ORed combinations of them:
    • maxmsg (int: -1)
      maxmsg is an upper limit on the number of messages that may be placed on the queue using send(). If omitted or specified as a negative number, the value in /proc/sys/fs/mqueue/msg_default is used. The maximum value for maxmsg is defined in /proc/sys/fs/mqueue/msg_max.
    • msgsize (int: -1)
      msgsize is an upper limit on the size of messages that may be placed on the queue. If omitted or specified as a negative number, the value in /proc/sys/fs/mqueue/msgsize_default is used. The maximum value for msgsize is defined in /proc/sys/fs/mqueue/msgsize_max.
close()
Closes the message queue.
fileno() -> int
Returns the underlying file descriptor of the message queue.
send(message) -> int
Sends one bytes-like message. Returns the number of bytes sent.
sendall(message)
Sends one bytes-like message. This calls send() repeatedly until all data is sent.
recv() -> bytes
Receives and returns one message.
name (read only)
This queue's name.
flags (read only)
flags argument passed to the constructor.
mode (read only)
File mode. The constants and functions in the stat module can be used to interpret it.
maxmsg (read only)
Maximum number of messages.
msgsize (read only)
Maximum message size (in bytes).
closed (read only)
True if the message queue is closed (i.e. close() has been called). False otherwise.
blocking
Get/set the blocking mode of the queue. Set to False if you want to put the queue in nonblocking mode. The initial blocking mode is set by the presence/absence of O_NONBLOCK in the flags argument passed to the constructor.