本文整理汇总了Python中stratum.pubsub.Pubsub.iterate_subscribers方法的典型用法代码示例。如果您正苦于以下问题:Python Pubsub.iterate_subscribers方法的具体用法?Python Pubsub.iterate_subscribers怎么用?Python Pubsub.iterate_subscribers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stratum.pubsub.Pubsub
的用法示例。
在下文中一共展示了Pubsub.iterate_subscribers方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_template
# 需要导入模块: from stratum.pubsub import Pubsub [as 别名]
# 或者: from stratum.pubsub.Pubsub import iterate_subscribers [as 别名]
def on_template(cls, is_new_block):
"""This is called when TemplateRegistry registers
new block which we have to broadcast clients."""
start = Interfaces.timestamper.time()
clean_jobs = is_new_block
(job_id, prevhash, coinb1, coinb2, merkle_branch, version, nbits, ntime, _) = \
Interfaces.template_registry.get_last_broadcast_args()
# Push new job to subscribed clients
for subscription in Pubsub.iterate_subscribers(cls.event):
try:
if subscription != None:
session = subscription.connection_ref().get_session()
session.setdefault('authorized', {})
if session['authorized'].keys():
worker_name = session['authorized'].keys()[0]
difficulty = session['difficulty']
work_id = Interfaces.worker_manager.register_work(worker_name, job_id, difficulty)
#log.debug("emitting for work id %s job id %s block %s " % (work_id, job_id, prevhash))
subscription.emit_single(work_id, prevhash, coinb1, coinb2, merkle_branch, version,
nbits, ntime, clean_jobs)
else:
subscription.emit_single(job_id, prevhash, coinb1, coinb2, merkle_branch, version,
nbits, ntime, clean_jobs)
except Exception as e:
log.exception("Error broadcasting work to client %s" % str(e))
pass
cnt = Pubsub.get_subscription_count(cls.event)
log.info("BROADCASTED to %d connections in %.03f sec" % (cnt, (Interfaces.timestamper.time() - start)))
示例2: print_subs
# 需要导入模块: from stratum.pubsub import Pubsub [as 别名]
# 或者: from stratum.pubsub.Pubsub import iterate_subscribers [as 别名]
def print_subs(cls):
c = Pubsub.get_subscription_count(cls.event)
log.info(c)
for subs in Pubsub.iterate_subscribers(cls.event):
s = Pubsub.get_subscription(
subs.connection_ref(),
cls.event,
key=None)
log.info(s)
示例3: get_server_stats
# 需要导入模块: from stratum.pubsub import Pubsub [as 别名]
# 或者: from stratum.pubsub.Pubsub import iterate_subscribers [as 别名]
def get_server_stats(self):
serialized = ''
for subscription in Pubsub.iterate_subscribers(self.event):
try:
if subscription != None:
session = subscription.connection_ref().get_session()
session.setdefault('authorized', {})
if session['authorized'].keys():
worker_name = session['authorized'].keys()[0]
difficulty = session['difficulty']
ip = subscription.connection_ref()._get_ip()
serialized += json.dumps({'worker_name': worker_name, 'ip': ip, 'difficulty': difficulty})
else:
pass
except Exception as e:
log.exception("Error getting subscriptions %s" % str(e))
pass
log.debug("Server stats request: %s" % serialized)
return '%s' % serialized
示例4: get_server_stats
# 需要导入模块: from stratum.pubsub import Pubsub [as 别名]
# 或者: from stratum.pubsub.Pubsub import iterate_subscribers [as 别名]
def get_server_stats(self):
serialized = ""
for subscription in Pubsub.iterate_subscribers(self.event):
try:
if subscription != None:
session = subscription.connection_ref().get_session()
session.setdefault("authorized", {})
if session["authorized"].keys():
worker_name = session["authorized"].keys()[0]
difficulty = session["difficulty"]
ip = subscription.connection_ref()._get_ip()
serialized += json.dumps({"worker_name": worker_name, "ip": ip, "difficulty": difficulty})
else:
pass
except Exception as e:
log.exception("Error getting subscriptions %s" % str(e))
pass
log.debug("Server stats request: %s" % serialized)
return "%s" % serialized
示例5: disconnect_all
# 需要导入模块: from stratum.pubsub import Pubsub [as 别名]
# 或者: from stratum.pubsub.Pubsub import iterate_subscribers [as 别名]
def disconnect_all(cls):
for subs in Pubsub.iterate_subscribers(cls.event):
subs.connection_ref().transport.loseConnection()
示例6: reconnect_all
# 需要导入模块: from stratum.pubsub import Pubsub [as 别名]
# 或者: from stratum.pubsub.Pubsub import iterate_subscribers [as 别名]
def reconnect_all(cls):
for subs in Pubsub.iterate_subscribers(cls.event):
if subs.connection_ref().transport is not None:
subs.connection_ref().transport.loseConnection()