本文整理汇总了Python中crypto2crypto.CryptoTransportLayer.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Python CryptoTransportLayer.shutdown方法的具体用法?Python CryptoTransportLayer.shutdown怎么用?Python CryptoTransportLayer.shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类crypto2crypto.CryptoTransportLayer
的用法示例。
在下文中一共展示了CryptoTransportLayer.shutdown方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MarketApplication
# 需要导入模块: from crypto2crypto import CryptoTransportLayer [as 别名]
# 或者: from crypto2crypto.CryptoTransportLayer import shutdown [as 别名]
class MarketApplication(tornado.web.Application):
def __init__(self, market_ip, market_port, market_id=1,
bm_user=None, bm_pass=None, bm_port=None, seed_peers=[],
seed_mode=0, dev_mode=False, db_path='db/ob.db'):
db = Obdb(db_path)
self.transport = CryptoTransportLayer(market_ip,
market_port,
market_id,
db,
bm_user,
bm_pass,
bm_port,
seed_mode,
dev_mode)
self.market = Market(self.transport, db)
def post_joined():
self.transport.dht._refreshNode()
self.market.republish_contracts()
peers = seed_peers if seed_mode == 0 else []
self.transport.join_network(peers)
Thread(target=reactor.run, args=(False,)).start()
handlers = [
(r"/", MainHandler),
(r"/main", MainHandler),
(r"/html/(.*)", OpenBazaarStaticHandler, {'path': './html'}),
(r"/ws", WebSocketHandler,
dict(transport=self.transport, market_application=self, db=db))
]
# TODO: Move debug settings to configuration location
settings = dict(debug=True)
tornado.web.Application.__init__(self, handlers, **settings)
def get_transport(self):
return self.transport
def setup_upnp_port_mappings(self, http_port, p2p_port):
upnp.PortMapper.DEBUG = False
print "Setting up UPnP Port Map Entry..."
# TODO: Add some setting whether or not to use UPnP
# if Settings.get(Settings.USE_UPNP_PORT_MAPPINGS):
self.upnp_mapper = upnp.PortMapper()
# TODO: Add some setting whether or not to clean all previous port
# mappings left behind by us
# if Settings.get(Settings.CLEAN_UPNP_PORT_MAPPINGS_ON_START):
# upnp_mapper.cleanMyMappings()
# for now let's always clean mappings every time.
self.upnp_mapper.clean_my_mappings()
# result_http_port_mapping = self.upnp_mapper.add_port_mapping(http_port,
# http_port)
# print ("UPnP HTTP Port Map configuration done (%s -> %s) => %s" %
# (str(http_port), str(http_port), str(result_http_port_mapping)))
result_tcp_p2p_mapping = self.upnp_mapper.add_port_mapping(p2p_port,
p2p_port)
print ("UPnP TCP P2P Port Map configuration done (%s -> %s) => %s" %
(str(p2p_port), str(p2p_port), str(result_tcp_p2p_mapping)))
result_udp_p2p_mapping = self.upnp_mapper.add_port_mapping(p2p_port,
p2p_port,
'UDP')
print ("UPnP UDP P2P Port Map configuration done (%s -> %s) => %s" %
(str(p2p_port), str(p2p_port), str(result_udp_p2p_mapping)))
# return result_http_port_mapping and \
return result_tcp_p2p_mapping and \
result_udp_p2p_mapping
def cleanup_upnp_port_mapping(self):
try:
if self.upnp_mapper is not None:
print "Cleaning UPnP Port Mapping -> ", \
self.upnp_mapper.clean_my_mappings()
except AttributeError:
print "[openbazaar] MarketApplication.clean_upnp_port_mapping() failed!"
pass
def shutdown(self, x=None, y=None):
print "MarketApplication.shutdown!"
locallogger = logging.getLogger('[%s] %s' % (self.market.market_id, 'root'))
locallogger.info("Received TERMINATE, exiting...")
# application.get_transport().broadcast_goodbye()
self.cleanup_upnp_port_mapping()
tornado.ioloop.IOLoop.instance().stop()
self.transport.shutdown()
os._exit(0)