简体   繁体   中英

Websockets alongside a python http server

I'm trying to figure out the best architecture to support connections to thousands of websockets alongside a managing HTTP server.

I want to be able to manage all of the connections through the HTTP server with minimum complexity.

Ideally, I am trying to merge:

  • An existing proprietary python library that uses the websockets package
  • A connexion (Flask-OpenAPI) application framework

Can these parts fit together?

Also, could this run under a WSGI server gracefully or must I transition to ASGI?

Any assistance, tips or pointers would be much appreciated. Thanks

Have you tried using threading where you can run multiple things at once. To start a thread it's simple just

from threading import Thread

def testT1():
    for x in range(20):
        print("printing from testT1")

def testT2():
    for x in range(20):
        print("printing from testT2")

Thread(target=testT1).start()
Thread(target=testT2).start()

This might not be the best example. But basically it allows to run multiple things even if testT1 blocks it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM