class Server(object): def __init__(self,host=None,port=None): set = Settings() self.logger = Logger() if host or port == None : host = set.get_item('core','server_host') port = set.get_item('core','server_port') self.host = host self.port = port Pyro4.config.HMAC_KEY = set.get_item('core','hmac_phrase') if is_ip_set(self.host): self.daemon = VinllaDaemon( host = self.host, port = self.port ) else : self.logger.critical( "[Server] Server can't bind to address %s, Node Manager not detect this IP belonging this Server" % self.host ) sys.exit() def hook_object(self,obj,id=None): if id == None : id = obj.__class__.__name__ self.uri = self.daemon.register(obj,objectId=id) def run(self): self.logger.success( "[Server] Node Manager Server successfuly run at %s" % (self.daemon.locationStr) ) self.daemon.requestLoop()
class HeartbeatFactory(protocol.ClientFactory): def __init__(self, libbitcoin_client): self.libbitcoin_client = libbitcoin_client self.log = Logger(system=self) def buildProtocol(self, addr): self.protocol = HeartbeatProtocol(self.libbitcoin_client) return self.protocol def clientConnectionFailed(self, connector, reason): self.libbitcoin_client.connected = False self.log.critical("Libbitcoin server offline")
class HeartbeatProtocol(protocol.Protocol): """ For listening on the libbitcoin server heartbeat port """ def __init__(self, libbitcoin_client): self.libbitcoin_client = libbitcoin_client self.timeout = reactor.callLater(7, self.call_timeout) self.log = Logger(system=self) def call_timeout(self): self.log.critical("Libbitcoin server offline") self.libbitcoin_client.connected = False def dataReceived(self, data): self.log.debug("libbitcoin heartbeat") self.timeout.cancel() self.libbitcoin_client.connected = True self.transport.loseConnection()
from log import Logger log = Logger() log.info("这是一个info信息") log.debug("这是一个debug信息") log.error("这是一个error信息") log.critical("这是一个critical信息")
cursor.close() if __name__ == "__main__": from misc import set_win, unset_win import traceback if sys.version_info.major >= 3: from io import StringIO else: from StringIO import StringIO try: main = BaseWindow(main=True) y, x = main.getWindow().getmaxyx() set_win() width = 20 edit = BaseWindow(width+1,0, y,x-(width+1)) itemlist = MyItemList(0, 0, y,width, mainwin = main) itemlist.getWindow().box() itemlist.redraw() itemlist.loop(edit) except Exception as e: fp = StringIO() traceback.print_exc(file=fp) message = fp.getvalue() logger.critical(message) finally: unset_win()
except JSONRPCError as ex: """ Error -25 is for attempted double spending (sending the same transaction twice). This is deliberately done by CoinParty as mixing peers broadcast each transaction concurrently. Thus, we just consume this error. """ if (ex.error['code'] != -25): raise IndexError( '%s.sendrawtransaction(): %s (%d)\nTransaction was:\n%s' % (self.__class__.__name__, ex.error['message'], ex.error['code'], str(tx))) # Define usage of mainnet or testnet SelectParams('testnet' if mstate.usingTestnet() else 'mainnet') try: bitcoind = Proxy() except BaseException as e: from sys import exit log.critical('Could not initialize bitcoind proxy: ' + str(e)) exit(1) def transaction_confirmed(txid, confirmations=6): """ Check whether the transaction referred to by txid has sufficiently many confirmations. """ try: tx = bitcoind.getrawtransaction(txid) return True if (tx['confirmations'] >= confirmations) else False except: return False