title: Using Websocket data on other functions
body: <p>I am calling websocket functions for particular data and want to use it later on other functions.
  However, I am noticing the websocket simply doesnt stop updating and doesnt go further to check the other functions.
  I guess this is due to calling ws.run_forever().</p>
  <p>What is the alternative? can you help me? Should I create a thread for  the websocket connection?</p>
  <p>Thanks</p>
  <pre><code>import json
  import websocket
  import os
  from math import pi
  from itertools import count
  from datetime import datetime, timedelta
  import time
  
  def on_message(ws,message):
      json_message = json.loads(message)
      cs = json_message
      for coin in cs:
        min_price[coin[&quot;s&quot;]] = { &quot;lastPrice&quot;: coin[&quot;c&quot;], &quot;lowPrice&quot;: coin[&quot;l&quot;]}
        with open(compare_coins, &quot;w&quot;) as file:
          json.dump(min_price, file, indent=4)
      is_candle_closed = candle['x']
      if is_candle_closed:
          print(json.dumps(candle, indent=2))
  
  
  ws = websocket.WebSocketApp(SOCK, on_open=on_open,on_close=on_close, on_message=on_message)
  ws.keep_running = True
  
  def check_below():
    volatile_coins = {}
    for coin in min_price:
      if float(min_price[coin][&quot;lastPrice&quot;])&gt;=float(min_price[coin][&quot;lowPrice&quot;]):
        volatile_coins[coin] = min_price[coin][&quot;lastPrice&quot;]
    return volatile_coins, len(volatile_coins), min_price
  </code></pre>