diff options
| author | bubbleboy14 <mario.balibrera@gmail.com> | 2021-12-13 11:39:18 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-13 14:39:18 -0500 |
| commit | 1abdc07951b1dc58eea4e148ef5ffe3d4d25df41 (patch) | |
| tree | c8330d8a41e426505adb5501f0eb53abdb217eda /docs | |
| parent | 0694848a93043b29e60c7653afb385839b1629b6 (diff) | |
| download | websocket-client-1abdc07951b1dc58eea4e148ef5ffe3d4d25df41.tar.gz | |
rel example (#770)
Add example of ws.run_forever(dispatcher) to demonstrate using dispatcher
* rel example
* tweaked rel example for linter
* added rel note to examples.rst
* slightly more compact example
* added example header
* matched wording
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/source/examples.rst | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/docs/source/examples.rst b/docs/source/examples.rst index 09e376f..29caf1c 100644 --- a/docs/source/examples.rst +++ b/docs/source/examples.rst @@ -663,6 +663,25 @@ by `issue #351 <https://github.com/websocket-client/websocket-client/issues/351> `Work in progress - coming soon` +Dispatching Multiple WebSocketApps +================================== + +You can use an asynchronous dispatcher such as `rel <https://pypi.org/project/rel/>`_ to run multiple WebSocketApps in the same application without resorting to threads. + +**WebSocketApp asynchronous dispatcher code example** + +:: + + import websocket, rel + + rel.safe_read() + addr = "wss://api.gemini.com/v1/marketdata/%s" + for symbol in ["BTCUSD", "ETHUSD", "ETHBTC"]: + ws = websocket.WebSocketApp(addr % (symbol,), on_message=lambda w, m : print(m)) + ws.run_forever(dispatcher=rel) + rel.signal(2, rel.abort) # Keyboard Interrupt + rel.dispatch() + Real-world Examples ========================= |
