mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-18 22:54:23 +01:00
pisa-btc initial commit
Contains basic structure, zmq so subscribe to blockid messages, api and so on. Still WIP
This commit is contained in:
34
pisa-btc/pisa/api.py
Normal file
34
pisa-btc/pisa/api.py
Normal file
@@ -0,0 +1,34 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user