<commit_before># run with
#   gunicorn -k flask_sockets.worker chain.websocketd:app
# make sure you've run setup.py to install flask_sockets

from __future__ import print_function

import zmq.green as zmq
import gevent
from flask import Flask
from flask_sockets import Sockets
from geventwebsocket import WebSocketError
from zmq_passthrough import passthrough
from chain.settings import ZMQ_PASSTHROUGH_URL_PUB

app = Flask(__name__)
app.debug = True
zmq_ctx = zmq.Context()
websockets = Sockets(app)


@websockets.route('/<tag>')
def site_socket(ws, tag):
    print('ws client connected for tag "%s"' % tag)
    zmq_sock = zmq_ctx.socket(zmq.SUB)
    zmq_sock.connect(ZMQ_PASSTHROUGH_URL_PUB)
    # note that flask gives us tag as a unicode string
    zmq_sock.setsockopt_string(zmq.SUBSCRIBE, tag)
    while True:
        in_data = zmq_sock.recv()
        # in case we later subscribe to multiple topic, get the topic from the
        # incoming message
        msg_tag, _, msg = in_data.partition(' ')
        print('Received on tag "%s": %s' % (msg_tag, msg))
        try:
            ws.send(msg)
        except WebSocketError as e:
            print('Caught WebSocketError: %s' % e)
            break
    zmq_sock.disconnect(ZMQ_PUB_URL)

# Start the passthrough process:
gevent.spawn(passthrough, zmq_context=zmq_ctx)<commit_msg>fixed outdated url in disconnect<commit_after># run with
#   gunicorn -k flask_sockets.worker chain.websocketd:app
# make sure you've run setup.py to install flask_sockets

from __future__ import print_function

import zmq.green as zmq
import gevent
from flask import Flask
from flask_sockets import Sockets
from geventwebsocket import WebSocketError
from zmq_passthrough import passthrough
from chain.settings import ZMQ_PASSTHROUGH_URL_PUB

app = Flask(__name__)
app.debug = True
zmq_ctx = zmq.Context()
websockets = Sockets(app)


@websockets.route('/<tag>')
def site_socket(ws, tag):
    print('ws client connected for tag "%s"' % tag)
    zmq_sock = zmq_ctx.socket(zmq.SUB)
    zmq_sock.connect(ZMQ_PASSTHROUGH_URL_PUB)
    # note that flask gives us tag as a unicode string
    zmq_sock.setsockopt_string(zmq.SUBSCRIBE, tag)
    while True:
        in_data = zmq_sock.recv()
        # in case we later subscribe to multiple topic, get the topic from the
        # incoming message
        msg_tag, _, msg = in_data.partition(' ')
        print('Received on tag "%s": %s' % (msg_tag, msg))
        try:
            ws.send(msg)
        except WebSocketError as e:
            print('Caught WebSocketError: %s' % e)
            break
    zmq_sock.disconnect(ZMQ_PASSTHROUGH_URL_PUB)

# Start the passthrough process:
gevent.spawn(passthrough, zmq_context=zmq_ctx)
{'fraction_non_alphanumeric': 0.0828708842027377, 'fraction_numerical': 0.0, 'mean_word_length': 3.606473594548552, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4780681', 'n_tokens_mistral': 957, 'n_tokens_neox': 905, 'n_words': 255}