/usr/share/pyshared/txzmq/factory.py is in python-txzmq 0.6.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | """
ZeroMQ Twisted factory which is controlling ZeroMQ context.
"""
from zmq.core.context import Context
from twisted.internet import reactor
class ZmqFactory(object):
"""
I control individual ZeroMQ connections.
Factory creates and destroys ZeroMQ context.
@cvar reactor: reference to Twisted reactor used by all the connections
@cvar ioThreads: number of IO threads ZeroMQ will be using for this context
@type ioThreads: C{int}
@cvar: lingerPeriod: number of milliseconds to block when closing socket
(terminating context), when there are some messages pending to be sent
@type lingerPeriod: C{int}
@ivar connections: set of instanciated L{ZmqConnection}s
@type connections: C{set}
@ivar context: ZeroMQ context
@type context: L{Context}
"""
reactor = reactor
ioThreads = 1
lingerPeriod = 100
def __init__(self):
"""
Constructor.
Create ZeroMQ context.
"""
self.connections = set()
self.context = Context(self.ioThreads)
def __repr__(self):
return "ZmqFactory()"
def shutdown(self):
"""
Shutdown factory.
This is shutting down all created connections
and terminating ZeroMQ context.
"""
for connection in self.connections.copy():
connection.shutdown()
self.connections = None
self.context.term()
self.context = None
def registerForShutdown(self):
"""
Register factory to be automatically shut down
on reactor shutdown.
"""
reactor.addSystemEventTrigger('during', 'shutdown', self.shutdown)
|