PGChannelListener

PGChannelListener TODO

Contents

class gDBPool.PGChannelListener.PGChannelListener(q, pool, channel_name)[source]

Bases: object

A Listener for Postgres LISTEN/NOTIFY channels using gevent.

For each channel there will be one :class:PGChannelListener instance that fans notifications out to the subscribed :class:Queue}

Create a Listener for a channel_name and pass the notifications to q result Queue.

Parameters:
  • q (gevent.Queue) – Queue to pass asynchronous payloads to
  • pool (gDBPool.DBConnectionPool) – Connection pool to get a connection from and execute LISTEN <channel_name>; on if no other instance listens on that channel already. In the latter case the q is just being subscribed to the channel.
  • channel_name (string) – channel to listen on. (LISTEN <channel_name>;)
Returns:

– PGChannelListener instance

unregister_queue(q_id)[source]

Unregister a Queue from its channel.

If it was the last subscriber stop listening on the channel and put the connection used back onto the pool.

Parameters:q_id – The id() of the Queue to be unsubscribed from the channel
listen(unmarshaller=<function pipe_colon_unmarshall at 0x3310848>)[source]

Subscriber to the channel and send notification payloads to the results Queue.

Parameters:unmarshaller (function) – Function to pass the notify.payload string into for unmarshalling into python object (ie. dict) data
gDBPool.PGChannelListener.pipe_colon_unmarshall(payload_string)[source]

Convert a pipe seperated string of <key:value> pairs as a dict

Parameters:payload_string (string) –
Returns:dict – unmarshalled NOTIFY data

Table Of Contents

Previous topic

gDBPool Usage

Next topic

DBConnectionPool

This Page