本文整理匯總了Python中zmq.log.handlers.PUBHandler.formatters方法的典型用法代碼示例。如果您正苦於以下問題:Python PUBHandler.formatters方法的具體用法?Python PUBHandler.formatters怎麽用?Python PUBHandler.formatters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類zmq.log.handlers.PUBHandler
的用法示例。
在下文中一共展示了PUBHandler.formatters方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: from zmq.log.handlers import PUBHandler [as 別名]
# 或者: from zmq.log.handlers.PUBHandler import formatters [as 別名]
def run(self):
context = zmq.Context()
pub = context.socket(zmq.PUB)
pub.connect(self.add_log)
self.log = logging.getLogger()
self.log.setLevel(logging.DEBUG)
handler = PUBHandler(pub)
handler.formatters = formatters
self.log.addHandler(handler)
self.log.debug('start_sink')
self.receiver = context.socket(zmq.PULL)
self.receiver.bind(self.add_rec)
self.controller = context.socket(zmq.PUB)
self.controller.bind(self.add_pub)
#socket to sinks
self.main = context.socket(zmq.PUSH)
self.main.connect(self.add_push)
# Message from main: start
self.receiver.recv()
#Measure time!
t_start = time.time()
results = []
for task_nbr in range(self.tasks):
raw_json_data = self.receiver.recv()
res = json.loads(
raw_json_data,
object_hook=MyOptResult.unserialize_object
)
results.append(res)
t_end = time.time()
t_duration = t_end - t_start
self.log.debug(
'Collected {count} results'.format(
count=len(results),
)
)
self.log.debug(
'Total elapsed time: {duration} s'.format(duration=t_duration)
)
self.controller.send(b'KILL')
self.handle_results(results)
time.sleep(1)
self.main.send(b'0')
示例2: _start_logger
# 需要導入模塊: from zmq.log.handlers import PUBHandler [as 別名]
# 或者: from zmq.log.handlers.PUBHandler import formatters [as 別名]
def _start_logger(context):
global log
controller = context.socket(zmq.PUB)
controller.bind(ADD_LOG_CONTROLLER)
l = Logger(ADD_LOGGING, ADD_LOG_LH_CONTROLLER)
l.start()
time.sleep(2)
pub = context.socket(zmq.PUB)
pub.connect(ADD_LH_LOGGING)
log = logging.getLogger('main')
log.setLevel(logging.DEBUG)
handler = PUBHandler(pub)
handler.formatters = formatters
log.addHandler(handler)
return controller