Files
python-teos/pisa-btc/pisa/api.py
Sergi Delgado 39a9a92bdb pisa-btc initial commit
Contains basic structure, zmq so subscribe to blockid messages, api and so on. Still WIP
2019-08-09 15:00:02 +01:00

35 lines
876 B
Python

import threading
from multiprocessing.connection import Listener
from pisa import *
def manage_api(debug, host=HOST, port=PORT):
listener = Listener((host, port))
while True:
conn = listener.accept()
if debug:
print('Connection accepted from', listener.last_accepted)
# Maintain metadata up to date.
t_serve = threading.Thread(target=serve_data, args=[debug, conn, listener.last_accepted])
t_serve.start()
def serve_data(debug, conn, remote_addr):
while not conn.closed:
try:
msg = conn.recv()
if type(msg) == tuple:
if len(msg) is 2:
command, arg = msg
print(command, arg)
except (IOError, EOFError):
if debug:
print('Disconnecting from', remote_addr)
conn.close()