stiqueue package

Submodules

stiqueue.peekqueue module

class stiqueue.peekqueue.PeekQueue(maxsize=0)[source]

Bases: Queue

A thread-safe queue that extends Queue to allow peeking at elements without removing them.

Warning

This implementation provides a non-intrusive peek method, but it still creates a deep copy of the internal queue. This operation may be expensive for large queues.

peek(n=0)[source]

Returns up to n items from the queue without removing them.

Unlike previous implementations, this method creates a deep copy of the queue’s internal deque, ensuring that the original queue remains unmodified.

Note

  • This method does not affect the order of items in the queue.

  • If n=0, it returns all available elements.

  • If n > queue size, it returns all elements.

Parameters:

n (int, optional) – The number of elements to peek. Defaults to 0 (all items).

Returns:

A list containing up to n items from the queue.

Return type:

List[Any]

Example

>>> pq = PeekQueue()
>>> pq.put(10)
>>> pq.put(20)
>>> pq.peek(1)
[10]
>>> pq.peek()
[10, 20]
>>> pq.get()
10
>>> pq.peek()
[20]

stiqueue.sqclient module

This module implements a simple client for interacting with a message queue server.

Classes:

SQClient: A client that connects to the message queue server to enqueue, dequeue, and check the count of messages.

class stiqueue.sqclient.SQClient(host='127.0.0.1', port=1234, logger=None, buff_size=None, ack_required=True)[source]

Bases: object

A client that connects to a message queue server for enqueuing, dequeuing, and retrieving the count of messages.

host

The server’s host address.

Type:

str

port

The port number to connect to the server.

Type:

int

socket

The client socket to communicate with the server.

Type:

socket.socket

buff_size

Buffer size for sending and receiving messages.

Type:

int

logger

Logger for printing messages.

Type:

logging.Logger

ack_required

Indicates whether an acknowledgment is required after the client receives the message.

Type:

bool

cnt()[source]

Sends a “count” request to the server and receives the count of messages in the queue.

Returns:

The count of messages in the queue.

Return type:

bytes

connect()[source]

Establishes a connection to the messaging queue server.

deq()[source]

Sends a “dequeue” request to the server and receives the dequeued message.

Returns:

The dequeued message from the server.

Return type:

bytes

disconnect()[source]

Closes the connection to the server.

enq(msg)[source]

Sends an “enqueue” request to the server.

Parameters:

msg (bytes or str) – The message to enqueue. If not in bytes, it will be encoded.

peek(n=0, sep='\t')[source]

Sends a “count” request to the server and receives the count of messages in the queue.

Returns:

The count of messages in the queue.

Return type:

bytes

send_with_action(msg, action, recv=False, ack=False)[source]

Sends a message with a specified action to the server, with optional acknowledgment.

This method connects to the server, sends a message prefixed with the specified action, and optionally waits for a response or sends an acknowledgment.

Parameters:
  • msg (bytes or str) – The message to send. If not in bytes, it will be encoded.

  • action (bytes) – The action command (e.g., “enq”, “deq”, “cnt”).

  • recv (bool) – Whether to expect a response from the server. Defaults to False.

  • ack (bool, optional) – Whether to send an acknowledgment after sending the message. Defaults to False.

Returns:

The server’s response if recv is True, otherwise None.

Return type:

bytes

stiqueue.sqserver module

Module contents