Flask executes the command and returns

1. At present, I have made a web version of the command execution using falsk-socketio, but it is found that it cannot be line-by-line

.
def shell(cmd, kwargs):
    print(">>>>>>>>> :%s" % cmd)
    program_name = kwargs.get("program_name")
    socketio_event = kwargs.get("socketio_event")
    socketio_sid = kwargs.get("socketio_sid")
    try:
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
        print(">>>>>>>>> : %s : %s ID:%s " % (socketio_sid, program_name, str(p.pid)))

        while p.poll() is None:
            res = p.stdout.readline()
            print(res)
            emit(socketio_event, str(res))

        for i in p.stdout.readlines():
            emit(socketio_event, str(i))
    except Exception as e:
        debug(e)
        return -1
    else:
        return 0

2. It is found that the ping command of tplink is completed with ajax request, how to implement the ping command of tplink using flask?

Mar.03,2021

refer to my demo gsw945/flask-sio-demo
there are correct and incorrect examples and instructions are given.
for your example, you only show the main code that is executed, and I don't know what your whole process looks like. If I can show the real process, I am interested in further answers.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf4767-31eda.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf4767-31eda.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?