• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python deferral.sleep函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中util.deferral.sleep函数的典型用法代码示例。如果您正苦于以下问题:Python sleep函数的具体用法?Python sleep怎么用?Python sleep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了sleep函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: download_shares

 def download_shares():
     while True:
         desired = yield desired_var.get_when_satisfies(lambda val: len(val) != 0)
         peer2, share_hash = random.choice(desired)
         
         if len(p2p_node.peers) == 0:
             yield deferral.sleep(1)
             continue
         peer = random.choice(p2p_node.peers.values())
         
         print 'Requesting parent share %s from %s' % (p2pool_data.format_hash(share_hash), '%s:%i' % peer.addr)
         try:
             shares = yield peer.get_shares(
                 hashes=[share_hash],
                 parents=500,
                 stops=[],
             )
         except:
             log.err(None, 'in download_shares:')
             continue
         
         if not shares:
             yield deferral.sleep(1) # sleep so we don't keep rerequesting the same share nobody has
             continue
         p2p_node.handle_shares(shares, peer)
开发者ID:alaudidae,项目名称:p2pool,代码行数:25,代码来源:main.py


示例2: new_share

 def new_share(share):
     if share.pow_hash <= share.header['bits'].target and abs(share.timestamp - time.time()) < 10*60:
         yield deferral.sleep(random.expovariate(1/60))
         message = '\x02%s BLOCK FOUND by %s! %s%064x' % (net.NAME.upper(), bitcoin_data.script2_to_address(share.new_script, net.PARENT), net.PARENT.BLOCK_EXPLORER_URL_PREFIX, share.header_hash)
         if all('%x' % (share.header_hash,) not in old_message for old_message in self.recent_messages):
             self.say(self.channel, message)
             self._remember_message(message)
开发者ID:alaudidae,项目名称:p2pool,代码行数:7,代码来源:main.py


示例3: work2_thread

 def work2_thread():
     while True:
         try:
             set_real_work2()
         except:
             log.err()
         yield deferral.sleep(random.expovariate(1/20))
开发者ID:gyver,项目名称:p2pool,代码行数:7,代码来源:main.py


示例4: work_poller

 def work_poller():
     while True:
         flag = factory.new_block.get_deferred()
         try:
             bitcoind_work.set((yield getwork(bitcoind, bitcoind_work.value['use_getblocktemplate'])))
         except:
             log.err()
         yield defer.DeferredList([flag, deferral.sleep(15)], fireOnOneCallback=True)
开发者ID:alaudidae,项目名称:p2pool,代码行数:8,代码来源:main.py


示例5: work1_thread

 def work1_thread():
     while True:
         flag = work_updated.get_deferred()
         try:
             yield set_real_work1()
         except:
             log.err()
         yield defer.DeferredList([flag, deferral.sleep(random.expovariate(1/20))], fireOnOneCallback=True)
开发者ID:gyver,项目名称:p2pool,代码行数:8,代码来源:main.py


示例6: status_thread

        def status_thread():
            last_str = None
            last_time = 0
            while True:
                yield deferral.sleep(3)
                try:
                    height = node.tracker.get_height(node.best_share_var.value)
                    this_str = 'P2Pool: %i shares in chain (%i verified/%i total) Peers: %i (%i incoming)' % (
                        height,
                        len(node.tracker.verified.items),
                        len(node.tracker.items),
                        len(node.p2p_node.peers),
                        sum(1 for peer in node.p2p_node.peers.itervalues() if peer.incoming),
                    ) + (' FDs: %i R/%i W' % (len(reactor.getReaders()), len(reactor.getWriters())) if p2pool.DEBUG else '')
                    
                    datums, dt = wb.local_rate_monitor.get_datums_in_last()
                    my_att_s = sum(datum['work']/dt for datum in datums)
                    my_shares_per_s = sum(datum['work']/dt/bitcoin_data.target_to_average_attempts(datum['share_target']) for datum in datums)
                    this_str += '\n Local: %sH/s in last %s Local dead on arrival: %s Expected time to share: %s' % (
                        math.format(int(my_att_s)),
                        math.format_dt(dt),
                        math.format_binomial_conf(sum(1 for datum in datums if datum['dead']), len(datums), 0.95),
                        math.format_dt(1/my_shares_per_s) if my_shares_per_s else '???',
                    )
                    
                    if height > 2:
                        (stale_orphan_shares, stale_doa_shares), shares, _ = wb.get_stale_counts()
                        stale_prop = p2pool_data.get_average_stale_prop(node.tracker, node.best_share_var.value, min(60*60//net.SHARE_PERIOD, height))
                        real_att_s = p2pool_data.get_pool_attempts_per_second(node.tracker, node.best_share_var.value, min(height - 1, 60*60//net.SHARE_PERIOD)) / (1 - stale_prop)
                        
                        this_str += '\n Shares: %i (%i orphan, %i dead) Stale rate: %s Efficiency: %s Current payout: %.4f %s' % (
                            shares, stale_orphan_shares, stale_doa_shares,
                            math.format_binomial_conf(stale_orphan_shares + stale_doa_shares, shares, 0.95),
                            math.format_binomial_conf(stale_orphan_shares + stale_doa_shares, shares, 0.95, lambda x: (1 - x)/(1 - stale_prop)),
                            node.get_current_txouts().get(bitcoin_data.pubkey_hash_to_script2(my_pubkey_hash), 0)*1e-8, net.PARENT.SYMBOL,
                        )
			print(node.bitcoind_work.value['bits'])
			print(real_att_s)
                        this_str += '\n Pool: %sH/s Stale rate: %.1f%% Expected time to block: %s' % (
                            math.format(int(real_att_s)),
                            100*stale_prop,
                            math.format_dt(2**256 / node.bitcoind_work.value['bits'].target / real_att_s),
                        )
                        
                        for warning in p2pool_data.get_warnings(node.tracker, node.best_share_var.value, net, bitcoind_getinfo_var.value, node.bitcoind_work.value):
                            print >>sys.stderr, '#'*40
                            print >>sys.stderr, '>>> Warning: ' + warning
                            print >>sys.stderr, '#'*40
                        
                        if gc.garbage:
                            print '%i pieces of uncollectable cyclic garbage! Types: %r' % (len(gc.garbage), map(type, gc.garbage))
                    
                    if this_str != last_str or time.time() > last_time + 15:
                        print this_str
                        last_str = this_str
                        last_time = time.time()
                except:
                    log.err()
开发者ID:ahmedbodi,项目名称:p2pool-dev-fee,代码行数:58,代码来源:main.py


示例7: set_merged_work

 def set_merged_work(merged_url, merged_userpass):
     merged_proxy = jsonrpc.HTTPProxy(merged_url, dict(Authorization='Basic ' + base64.b64encode(merged_userpass)))
     while self.running:
         auxblock = yield deferral.retry('Error while calling merged getauxblock on %s:' % (merged_url,), 30)(merged_proxy.rpc_getauxblock)()
         self.merged_work.set(math.merge_dicts(self.merged_work.value, {auxblock['chainid']: dict(
             hash=int(auxblock['hash'], 16),
             target='p2pool' if auxblock['target'] != 'p2pool' else pack.IntType(256).unpack(auxblock['target'].decode('hex')),
             merged_proxy=merged_proxy,
         )}))
         yield deferral.sleep(1)
开发者ID:cqtenq,项目名称:p2pool-neoscrypt,代码行数:10,代码来源:work.py


示例8: upnp_thread

 def upnp_thread():
     while True:
         try:
             is_lan, lan_ip = yield ipdiscover.get_local_ip()
             if not is_lan:
                 continue
             pm = yield portmapper.get_port_mapper()
             yield pm._upnp.add_port_mapping(lan_ip, args.net.P2P_PORT, args.net.P2P_PORT, 'p2pool', 'TCP')
         except:
             if p2pool_init.DEBUG:
                 log.err()
         yield deferral.sleep(random.expovariate(1/120))
开发者ID:gyver,项目名称:p2pool,代码行数:12,代码来源:main.py


示例9: set_merged_work

 def set_merged_work():
     if not args.merged_url:
         return
     merged = jsonrpc.Proxy(args.merged_url, (args.merged_userpass,))
     while True:
         auxblock = yield deferral.retry('Error while calling merged getauxblock:', 1)(merged.rpc_getauxblock)()
         pre_merged_work.set(dict(
             hash=int(auxblock['hash'], 16),
             target=bitcoin_data.HashType().unpack(auxblock['target'].decode('hex')),
             chain_id=auxblock['chainid'],
         ))
         yield deferral.sleep(1)
开发者ID:finway-china,项目名称:p2pool,代码行数:12,代码来源:main.py


示例10: upnp_thread

 def upnp_thread():
     while True:
         try:
             is_lan, lan_ip = yield ipdiscover.get_local_ip()
             if is_lan:
                 pm = yield portmapper.get_port_mapper()
                 yield pm._upnp.add_port_mapping(lan_ip, args.p2pool_port, args.p2pool_port, 'p2pool', 'TCP')
         except defer.TimeoutError:
             pass
         except:
             if p2pool.DEBUG:
                 log.err(None, 'UPnP error:')
         yield deferral.sleep(random.expovariate(1/120))
开发者ID:and-then,项目名称:p2pool-rav,代码行数:13,代码来源:main.py


示例11: status_thread

 def status_thread():
     last_str = None
     last_time = 0
     while True:
         yield deferral.sleep(3)
         try:
             if time.time() > current_work2.value['last_update'] + 60:
                 print '''---> LOST CONTACT WITH BITCOIND for 60 seconds, check that it isn't frozen or dead <---'''
             if current_work.value['best_share_hash'] is not None:
                 height, last = tracker.get_height_and_last(current_work.value['best_share_hash'])
                 if height > 2:
                     att_s = p2pool_data.get_pool_attempts_per_second(tracker, current_work.value['best_share_hash'], min(height - 1, 720))
                     weights, total_weight, donation_weight = tracker.get_cumulative_weights(current_work.value['best_share_hash'], min(height, 720), 65535*2**256)
                     shares, stale_doa_shares, stale_not_doa_shares = get_share_counts(True)
                     stale_shares = stale_doa_shares + stale_not_doa_shares
                     fracs = [share.stale_frac for share in tracker.get_chain(current_work.value['best_share_hash'], min(120, height)) if share.stale_frac is not None]
                     this_str = 'Pool: %sH/s in %i shares (%i/%i verified) Recent: %.02f%% >%sH/s Shares: %i (%i orphan, %i dead) Peers: %i' % (
                         math.format(int(att_s / (1. - (math.median(fracs) if fracs else 0)))),
                         height,
                         len(tracker.verified.shares),
                         len(tracker.shares),
                         weights.get(my_script, 0)/total_weight*100,
                         math.format(int(weights.get(my_script, 0)*att_s//total_weight / (1. - (math.median(fracs) if fracs else 0)))),
                         shares,
                         stale_not_doa_shares,
                         stale_doa_shares,
                         len(p2p_node.peers),
                     ) + (' FDs: %i R/%i W' % (len(reactor.getReaders()), len(reactor.getWriters())) if p2pool.DEBUG else '')
                     if fracs:
                         med = math.median(fracs)
                         this_str += '\nPool stales: %i%%' % (int(100*med+.5),)
                         conf = 0.95
                         if shares:
                             this_str += u' Own: %i±%i%%' % tuple(int(100*x+.5) for x in math.interval_to_center_radius(math.binomial_conf_interval(stale_shares, shares, conf)))
                             if med < .99:
                                 this_str += u' Own efficiency: %i±%i%%' % tuple(int(100*x+.5) for x in math.interval_to_center_radius((1 - y)/(1 - med) for y in math.binomial_conf_interval(stale_shares, shares, conf)[::-1]))
                     if this_str != last_str or time.time() > last_time + 15:
                         print this_str
                         last_str = this_str
                         last_time = time.time()
         except:
             log.err()
开发者ID:finway-china,项目名称:p2pool,代码行数:42,代码来源:main.py


示例12: set_merged_work

 def set_merged_work(merged_url, merged_userpass):
     merged_proxy = jsonrpc.Proxy(merged_url, dict(Authorization="Basic " + base64.b64encode(merged_userpass)))
     while self.running:
         auxblock = yield deferral.retry("Error while calling merged getauxblock:", 30)(
             merged_proxy.rpc_getauxblock
         )()
         self.merged_work.set(
             dict(
                 self.merged_work.value,
                 **{
                     auxblock["chainid"]: dict(
                         hash=int(auxblock["hash"], 16),
                         target="p2pool"
                         if auxblock["target"] == "p2pool"
                         else pack.IntType(256).unpack(auxblock["target"].decode("hex")),
                         merged_proxy=merged_proxy,
                     )
                 }
             )
         )
         yield deferral.sleep(1)
开发者ID:hua002,项目名称:p2pool,代码行数:21,代码来源:work.py


示例13: main


#.........这里部分代码省略.........
            mode=0 if args.low_bandwidth else 1,
            preferred_addrs=set(map(parse, args.p2pool_nodes)) | nodes,
        )
        p2p_node.handle_shares = p2p_shares
        p2p_node.handle_share_hashes = p2p_share_hashes
        p2p_node.handle_get_shares = p2p_get_shares
        
        p2p_node.start()
        
        # send share when the chain changes to their chain
        def work_changed(new_work):
            #print 'Work changed:', new_work
            for share in tracker.get_chain_known(new_work['best_share_hash']):
                if share.shared:
                    break
                share_share(share, share.peer)
        current_work.changed.watch(work_changed)
        
        print '    ...success!'
        print
        
        @defer.inlineCallbacks
        def upnp_thread():
            while True:
                try:
                    is_lan, lan_ip = yield ipdiscover.get_local_ip()
                    if not is_lan:
                        continue
                    pm = yield portmapper.get_port_mapper()
                    yield pm._upnp.add_port_mapping(lan_ip, args.net.P2P_PORT, args.net.P2P_PORT, 'p2pool', 'TCP')
                except:
                    if p2pool_init.DEBUG:
                        log.err()
                yield deferral.sleep(random.expovariate(1/120))
        
        if args.upnp:
            upnp_thread()
         
        # start listening for workers with a JSON-RPC server
        
        print 'Listening for workers on port %i...' % (args.worker_port,)
        
        # setup worker logic
        
        merkle_root_to_transactions = expiring_dict.ExpiringDict(300)
        run_identifier = struct.pack('<Q', random.randrange(2**64))
        
        def compute(state, payout_script):
            if payout_script is None:
                payout_script = my_script
            if state['best_share_hash'] is None and args.net.PERSIST:
                raise jsonrpc.Error(-12345, u'p2pool is downloading shares')
            pre_extra_txs = [tx for tx in tx_pool.itervalues() if tx.is_good()]
            pre_extra_txs = pre_extra_txs[:2**16 - 1] # merkle_branch limit
            extra_txs = []
            size = 0
            for tx in pre_extra_txs:
                this_size = len(bitcoin.data.tx_type.pack(tx.tx))
                if size + this_size > 500000:
                    break
                extra_txs.append(tx)
                size += this_size
            # XXX check sigops!
            # XXX assuming generate_tx is smallish here..
            generate_tx = p2pool.generate_transaction(
                tracker=tracker,
开发者ID:gyver,项目名称:p2pool,代码行数:67,代码来源:main.py



注:本文中的util.deferral.sleep函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python elastalert_logger.info函数代码示例发布时间:2022-05-26
下一篇:
Python deferral.retry函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap