title: Why is my websocket-client stopping all of my subsequent code, and what can I do about it?
body: <p>I am setting up a python program to pull cryptocurrency data from binance, but the websocket that I am using pauses all code after it executes.</p>
  <pre><code>import websockets
  import websocket, json
  import asyncio
  
  def establishDefaultConnection():
      #websocket.enableTrace(True)
      def on_open(message):
          ws.send(loginStr)
          print(&quot;The default connection was opened&quot;)
  
      def pipeData(ws, message):
          print(message)
  
      def on_error(ws, message):
          print(message)
  
      def on_close(message):
          print(&quot;She gone&quot;)
  
      # Declare some variables
      socket = &quot;wss://stream.binance.us:9443/stream?streams=&quot;
      loginStr = '{&quot;method&quot;: &quot;SUBSCRIBE&quot;,&quot;params&quot;: [&quot;btcusd@kline_1m&quot;,&quot;btcusd@kline_3m&quot;],&quot;id&quot;: 1}'
  
      ws = websocket.WebSocketApp(socket, on_open=on_open, on_message=pipeData, on_error=on_error, on_close=on_close)
      ws.run_forever()
  
  establishDefaultConnection())
  print(&quot;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;Code was executed later&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&quot;)
  </code></pre>
  <p>The print command will never run, nor will anything after the command &quot;ws.run_forever()&quot;. In this web-sockets <a href="https://websocket-client.readthedocs.io/en/latest/app.html#websocket._app.WebSocketApp.run_forever" rel="nofollow noreferrer">documentation</a>, that command in stated to be a loop, but I can't tell what its looping on.</p>
  <p>I have tried setting up an asynchronous operation, but that hasn't worked out yet - though that could be my fault, since I am still learning how to use asyncio</p>
  <p>Any help here would be much appreciated - I will be online for the next 2 hours to immediately answer questions or talk about this issue.</p>
  <p>EDIT: I want to note that this websocket does indeed work - it streams in data just fine, but no other code runs. Also, any comments about my methodology would also be appreciated - again, I'm new to python and network/asynchronous coding.</p>