本文整理汇总了Python中network.Network.get_status_value方法的典型用法代码示例。如果您正苦于以下问题:Python Network.get_status_value方法的具体用法?Python Network.get_status_value怎么用?Python Network.get_status_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network.Network
的用法示例。
在下文中一共展示了Network.get_status_value方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NetworkServer
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import get_status_value [as 别名]
class NetworkServer(util.DaemonThread):
def __init__(self, config):
util.DaemonThread.__init__(self)
self.debug = False
self.config = config
self.pipe = util.QueuePipe()
self.network = Network(self.pipe, config)
self.lock = threading.RLock()
# each GUI is a client of the daemon
self.clients = []
self.request_id = 0
self.requests = {}
def add_client(self, client):
for key in ['status', 'banner', 'updated', 'servers', 'interfaces']:
value = self.network.get_status_value(key)
client.response_queue.put({'method':'network.status', 'params':[key, value]})
with self.lock:
self.clients.append(client)
print_error("new client:", len(self.clients))
def remove_client(self, client):
with self.lock:
self.clients.remove(client)
print_error("client quit:", len(self.clients))
def send_request(self, client, request):
with self.lock:
self.request_id += 1
self.requests[self.request_id] = (request['id'], client)
request['id'] = self.request_id
if self.debug:
print_error("-->", request)
self.pipe.send(request)
def run(self):
self.network.start()
while self.is_running():
try:
response = self.pipe.get()
except util.timeout:
continue
if self.debug:
print_error("<--", response)
response_id = response.get('id')
if response_id:
with self.lock:
client_id, client = self.requests.pop(response_id)
response['id'] = client_id
client.response_queue.put(response)
else:
# notification
m = response.get('method')
v = response.get('params')
for client in self.clients:
if m == 'network.status' or v in client.subscriptions.get(m, []):
client.response_queue.put(response)
self.network.stop()
print_error("server exiting")
示例2: NetworkServer
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import get_status_value [as 别名]
class NetworkServer(threading.Thread):
def __init__(self, config):
threading.Thread.__init__(self)
self.daemon = True
self.config = config
self.network = Network(config)
# network sends responses on that queue
self.network_queue = Queue.Queue()
self.running = False
self.lock = threading.RLock()
# each GUI is a client of the daemon
self.clients = []
# todo: the daemon needs to know which client subscribed to which address
def is_running(self):
with self.lock:
return self.running
def stop(self):
with self.lock:
self.running = False
def start(self):
self.running = True
threading.Thread.start(self)
def add_client(self, client):
for key in ['status','banner','updated','servers','interfaces']:
value = self.network.get_status_value(key)
client.daemon_pipe.get_queue.put({'method':'network.status', 'params':[key, value]})
with self.lock:
self.clients.append(client)
def remove_client(self, client):
with self.lock:
self.clients.remove(client)
print_error("client quit:", len(self.clients))
def run(self):
self.network.start(self.network_queue)
while self.is_running():
try:
response = self.network_queue.get(timeout=0.1)
except Queue.Empty:
continue
for client in self.clients:
client.daemon_pipe.get_queue.put(response)
self.network.stop()
print_error("server exiting")
示例3: NetworkServer
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import get_status_value [as 别名]
class NetworkServer(threading.Thread):
def __init__(self, config):
threading.Thread.__init__(self)
self.daemon = True
self.debug = False
self.config = config
self.network = Network(config)
# network sends responses on that queue
self.network_queue = Queue.Queue()
self.running = False
self.lock = threading.RLock()
# each GUI is a client of the daemon
self.clients = []
self.request_id = 0
self.requests = {}
def is_running(self):
with self.lock:
return self.running
def stop(self):
with self.lock:
self.running = False
def start(self):
self.running = True
threading.Thread.start(self)
def add_client(self, client):
for key in ['status','banner','updated','servers','interfaces']:
value = self.network.get_status_value(key)
client.response_queue.put({'method':'network.status', 'params':[key, value]})
with self.lock:
self.clients.append(client)
print_error("new client:", len(self.clients))
def remove_client(self, client):
with self.lock:
self.clients.remove(client)
print_error("client quit:", len(self.clients))
def send_request(self, client, request):
with self.lock:
self.request_id += 1
self.requests[self.request_id] = (request['id'], client)
request['id'] = self.request_id
if self.debug:
print_error("-->", request)
self.network.requests_queue.put(request)
def run(self):
self.network.start(self.network_queue)
while self.is_running():
try:
response = self.network_queue.get(timeout=0.1)
except Queue.Empty:
continue
if self.debug:
print_error("<--", response)
response_id = response.get('id')
if response_id:
with self.lock:
client_id, client = self.requests.pop(response_id)
response['id'] = client_id
client.response_queue.put(response)
else:
# notification
for client in self.clients:
client.response_queue.put(response)
self.network.stop()
print_error("server exiting")
示例4: NetworkProxy
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import get_status_value [as 别名]
class NetworkProxy(threading.Thread):
def __init__(self, socket, config=None):
if config is None:
config = {} # Do not use mutables as default arguments!
threading.Thread.__init__(self)
self.config = SimpleConfig(config) if type(config) == type({}) else config
self.message_id = 0
self.unanswered_requests = {}
self.subscriptions = {}
self.debug = False
self.lock = threading.Lock()
self.pending_transactions_for_notifications = []
self.callbacks = {}
self.running = True
self.daemon = True
if socket:
self.pipe = util.SocketPipe(socket)
self.network = None
else:
self.network = Network(config)
self.pipe = util.QueuePipe(send_queue=self.network.requests_queue)
self.network.start(self.pipe.get_queue)
for key in ['status', 'banner', 'updated', 'servers', 'interfaces']:
value = self.network.get_status_value(key)
self.pipe.get_queue.put({'method': 'network.status', 'params': [key, value]})
# status variables
self.status = 'connecting'
self.servers = {}
self.banner = ''
self.blockchain_height = 0
self.server_height = 0
self.interfaces = []
def is_running(self):
return self.running
def run(self):
while self.is_running():
try:
response = self.pipe.get()
except util.timeout:
continue
if response is None:
break
self.process(response)
self.trigger_callback('stop')
if self.network:
self.network.stop()
print_error("NetworkProxy: terminating")
def process(self, response):
if self.debug:
print_error("<--", response)
if response.get('method') == 'network.status':
key, value = response.get('params')
if key == 'status':
self.status = value
elif key == 'banner':
self.banner = value
elif key == 'updated':
self.blockchain_height, self.server_height = value
elif key == 'servers':
self.servers = value
elif key == 'interfaces':
self.interfaces = value
self.trigger_callback(key)
return
msg_id = response.get('id')
result = response.get('result')
error = response.get('error')
if msg_id is not None:
with self.lock:
method, params, callback = self.unanswered_requests.pop(msg_id)
else:
method = response.get('method')
params = response.get('params')
with self.lock:
for k, v in self.subscriptions.items():
if (method, params) in v:
callback = k
break
else:
print_error("received unexpected notification", method, params)
return
r = {'method':method, 'params':params, 'result':result, 'id':msg_id, 'error':error}
callback(r)
def send(self, messages, callback):
"""return the ids of the requests that we sent"""
# detect subscriptions
sub = []
#.........这里部分代码省略.........
示例5: NetworkProxy
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import get_status_value [as 别名]
class NetworkProxy(util.DaemonThread):
def __init__(self, socket, config=None):
if config is None:
config = {} # Do not use mutables as default arguments!
util.DaemonThread.__init__(self)
self.config = SimpleConfig(config) if type(config) == type({}) else config
self.message_id = 0
self.unanswered_requests = {}
self.subscriptions = {}
self.debug = False
self.lock = threading.Lock()
self.callbacks = {}
if socket:
self.pipe = util.SocketPipe(socket)
self.network = None
else:
self.pipe = util.QueuePipe()
self.network = Network(self.pipe, config)
self.network.start()
for key in ['fee','status','banner','updated','servers','interfaces']:
value = self.network.get_status_value(key)
self.pipe.get_queue.put({'method':'network.status', 'params':[key, value]})
# status variables
self.status = 'unknown'
self.servers = {}
self.banner = ''
self.blockchain_height = 0
self.server_height = 0
self.interfaces = []
# value returned by estimatefee
self.fee = None
def run(self):
while self.is_running():
self.run_jobs() # Synchronizer and Verifier
try:
response = self.pipe.get()
except util.timeout:
continue
if response is None:
break
# Protect against ill-formed or malicious server responses
try:
self.process(response)
except:
traceback.print_exc(file=sys.stderr)
self.trigger_callback('stop')
if self.network:
self.network.stop()
self.print_error("stopped")
def process(self, response):
if self.debug:
self.print_error("<--", response)
if response.get('method') == 'network.status':
key, value = response.get('params')
if key == 'status':
self.status = value
elif key == 'banner':
self.banner = value
elif key == 'fee':
self.fee = value
elif key == 'updated':
self.blockchain_height, self.server_height = value
elif key == 'servers':
self.servers = value
elif key == 'interfaces':
self.interfaces = value
if key in ['status', 'updated']:
self.trigger_callback(key)
else:
self.trigger_callback(key, (value,))
return
msg_id = response.get('id')
result = response.get('result')
error = response.get('error')
if msg_id is not None:
with self.lock:
method, params, callback = self.unanswered_requests.pop(msg_id)
else:
method = response.get('method')
params = response.get('params')
with self.lock:
for k,v in self.subscriptions.items():
if (method, params) in v:
callback = k
break
else:
self.print_error("received unexpected notification",
method, params)
return
r = {'method':method, 'params':params, 'result':result,
#.........这里部分代码省略.........
示例6: NetworkProxy
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import get_status_value [as 别名]
class NetworkProxy(util.DaemonThread):
def __init__(self, socket, config=None):
if config is None:
config = {} # Do not use mutables as default arguments!
util.DaemonThread.__init__(self)
self.config = SimpleConfig(config) if type(config) == type({}) else config
self.message_id = 0
self.unanswered_requests = {}
self.subscriptions = {}
self.debug = False
self.lock = threading.Lock()
self.callbacks = {}
if socket:
self.pipe = util.SocketPipe(socket)
self.network = None
else:
self.pipe = util.QueuePipe()
self.network = Network(self.pipe, config)
self.network.start()
for key in ["fee", "status", "banner", "updated", "servers", "interfaces"]:
value = self.network.get_status_value(key)
self.pipe.get_queue.put({"method": "network.status", "params": [key, value]})
# status variables
self.status = "unknown"
self.servers = {}
self.banner = ""
self.blockchain_height = 0
self.server_height = 0
self.interfaces = []
self.jobs = []
# value returned by estimatefee
self.fee = None
def run(self):
while self.is_running():
for job in self.jobs:
job()
try:
response = self.pipe.get()
except util.timeout:
continue
if response is None:
break
self.process(response)
self.trigger_callback("stop")
if self.network:
self.network.stop()
self.print_error("stopped")
def process(self, response):
if self.debug:
print_error("<--", response)
if response.get("method") == "network.status":
key, value = response.get("params")
if key == "status":
self.status = value
elif key == "banner":
self.banner = value
elif key == "fee":
self.fee = value
elif key == "updated":
self.blockchain_height, self.server_height = value
elif key == "servers":
self.servers = value
elif key == "interfaces":
self.interfaces = value
if key in ["status", "updated"]:
self.trigger_callback(key)
else:
self.trigger_callback(key, (value,))
return
msg_id = response.get("id")
result = response.get("result")
error = response.get("error")
if msg_id is not None:
with self.lock:
method, params, callback = self.unanswered_requests.pop(msg_id)
else:
method = response.get("method")
params = response.get("params")
with self.lock:
for k, v in self.subscriptions.items():
if (method, params) in v:
callback = k
break
else:
print_error("received unexpected notification", method, params)
return
r = {"method": method, "params": params, "result": result, "id": msg_id, "error": error}
callback(r)
def send(self, messages, callback):
"""return the ids of the requests that we sent"""
#.........这里部分代码省略.........
示例7: NetworkProxy
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import get_status_value [as 别名]
class NetworkProxy(util.DaemonThread):
"""Proxy for communicating with the daemon or Network.
If the daemon is running when this is initialized,
this will create a socket pipe.
Otherwise, this will create a new Network instance."""
def __init__(self, socket, config=None):
if config is None:
config = {} # Do not use mutables as default arguments!
util.DaemonThread.__init__(self)
self.config = SimpleConfig(config) if type(config) == type({}) else config
self.message_id = 0
self.unanswered_requests = {}
self.subscriptions = {}
self.debug = False
self.lock = threading.Lock()
self.pending_transactions_for_notifications = []
self.callbacks = {}
if socket:
self.pipe = util.SocketPipe(socket)
self.network = None
else:
self.pipe = util.QueuePipe()
self.network = Network(self.pipe, config)
self.network.start()
for key in ['status','banner','updated','servers','interfaces']:
value = self.network.get_status_value(key)
self.pipe.get_queue.put({'method':'network.status', 'params':[key, value]})
# status variables
self.status = 'connecting'
self.servers = {}
self.banner = ''
self.blockchain_height = 0
self.server_height = 0
self.interfaces = []
def switch_to_active_chain(self):
"""Create a new Network instance or send message to daemon."""
with self.lock:
# for the network.switch_chains request
message_id = self.message_id
self.message_id = 0
self.unanswered_requests = {}
self.subscriptions = {}
self.pending_transactions_for_notifications = []
self.callbacks = {}
self.status = 'connecting'
self.servers = {}
self.banner = ''
self.blockchain_height = 0
self.server_height = 0
self.interfaces = []
# Not daemon, probably running GUI
if self.network:
self.network.switch_chains()
for key in ['status','banner','updated','servers','interfaces']:
value = self.network.get_status_value(key)
self.pipe.get_queue.put({'method':'network.status', 'params':[key, value]})
# Daemon is running
else:
req = {'id': message_id, 'method': 'network.switch_chains', 'params':[chainparams.get_active_chain().code]}
self.pipe.send(req)
def run(self):
while self.is_running():
try:
response = self.pipe.get()
except util.timeout:
continue
if response is None:
break
self.process(response)
self.trigger_callback('stop')
if self.network:
self.network.stop()
self.print_error("stopped")
def process(self, response):
if self.debug:
print_error("<--", response)
if response.get('method') == 'network.status':
key, value = response.get('params')
if key == 'status':
self.status = value
elif key == 'banner':
self.banner = value
elif key == 'updated':
self.blockchain_height, self.server_height = value
elif key == 'servers':
#.........这里部分代码省略.........
示例8: NetworkServer
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import get_status_value [as 别名]
class NetworkServer(util.DaemonThread):
"""Server that the daemon sends connections to.
Handles requests/responses to/from the Network
from ClientThreads. Also handles notifying
ClientThreads of responses to their subscriptions."""
def __init__(self, config):
util.DaemonThread.__init__(self)
self.debug = False
self.config = config
self.pipe = util.QueuePipe()
self.network = Network(self.pipe, config)
self.lock = threading.RLock()
# each GUI is a client of the daemon
self.clients = []
self.request_id = 0
# dict of {request_id: client}
self.requests = {}
def add_client(self, client):
for key in ['status', 'banner', 'updated', 'servers', 'interfaces']:
value = self.network.get_status_value(key)
client.response_queue.put({'method':'network.status', 'params':[key, value]})
with self.lock:
self.clients.append(client)
print_error("new client:", len(self.clients))
def remove_client(self, client):
with self.lock:
self.clients.remove(client)
print_error("client quit:", len(self.clients))
def send_request(self, client, request):
with self.lock:
self.request_id += 1
self.requests[self.request_id] = (request['id'], client)
request['id'] = self.request_id
if self.debug:
print_error("-->", request)
self.pipe.send(request)
def run(self):
self.network.start()
while self.is_running():
try:
response = self.pipe.get()
except util.timeout:
continue
if self.debug:
print_error("<--", response)
response_id = response.get('id')
if response_id:
with self.lock:
client_id, client = self.requests.pop(response_id)
response['id'] = client_id
client.response_queue.put(response)
else:
# responses with no id are notifications (e.g. to subscriptions)
# and are sent to whichever clients have the subscription.
m = response.get('method')
v = response.get('params')
for client in self.clients:
if repr((m, v)) in client.subscriptions or m == 'network.status':
client.response_queue.put(response)
self.network.stop()
print_error("server exiting")