Serial Communication, Flask-SocketIO, and Python Multithreading
<p>My question is related to having an Arduino Uno communicate data through a socket to another client app. [A buzzer system communicating to a Jeopardy!-esque game frontend] To goal is to have the 'lockout' event emit.</p>

<p>Currently, the Arduino is running on its own thread and the Flask-SocketIO server is running as the main process. All code works, including the print statement saying "Emitting Socket", except for the line emitting the socket data after.</p>

<p>I feel like this is just a multithreading issue, but my experience with multithreading is minimal.</p>

<p>Suggestions?</p>

<pre><code># https://pymotw.com/2/threading/
# https://flask-socketio.readthedocs.org/en/latest/

import serial, time, threading

from flask import Flask, render_template
from flask_socketio import SocketIO

ser = serial.Serial('/dev/tty.usbmodem3d11', 9600, dsrdtr=1)
PORT = 3000

# Needed b/c Macs &amp; DTR
time.sleep(5)

def getSerialData():
    while True:
        stuff = str(ser.readline().decode("utf-8"))
        doEmit(1)

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)

def doEmit(pNo):
    print("Emitting Socket")
    socketio.emit('lockout', {'playerNo': 1})

serialThread = threading.Thread(name='serialThread', target=getSerialData)
serialThread.start()

@socketio.on("questionRead")
def on_questionRead(data):
    print("-------Start-------")
    ser.write(b'y\r')

@socketio.on("resetLockout")
def on_resetLockout(data):
    resetLockout()

def resetLockout():
    print("--------Reset--------")
    ser.write(b'n\r')

if __name__ == '__main__':
    socketio.run(app, '127.0.0.1', PORT)
</code></pre>