Skip to main content

python multiprocessing websocket server

Project description

parallel_websocket_server

run websocket server in parallel (using multiprocessing)

You can run the websocket server as a subprocess while keeping the main process distinct.

You can implement the main process without having to pay attention to the server.

Installation

pip install parallel_websocket_server

How to use

import json
import random
import multiprocessing as mp
from parallel_websocket_server import ParallelWebSocketServer


if __name__ == "__main__":
    receive_queue = mp.Queue()
    send_queue = mp.Queue()

    server = ParallelWebSocketServer(receive_queue, send_queue)

    while True:
        if not receive_queue.empty():
            received_message = receive_queue.get_nowait()
            print(received_message)

        ran = random.random()
        if ran < 0.00001:
            send_queue.put(json.dumps({"hoge": 1}))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

parallel_websocket_server-0.1.3.tar.gz (1.8 kB view hashes)

Uploaded Source

Built Distribution

parallel_websocket_server-0.1.3-py3-none-any.whl (2.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page