Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask-SocketIO auto client send disconnect to server #1209

Closed
yanxiaoyan2020 opened this issue Mar 18, 2020 · 29 comments
Closed

Flask-SocketIO auto client send disconnect to server #1209

yanxiaoyan2020 opened this issue Mar 18, 2020 · 29 comments
Labels

Comments

@yanxiaoyan2020
Copy link

yanxiaoyan2020 commented Mar 18, 2020

Your question
Hi Flask-SocketIO team
I don't know why the client(browser) auto send disconnect event to web server. My design is that web server receives disconnect event when the client(browser) close or switch other tab page. So this is issue that I need to resolve.
How can I change disconnect. Thank you
Best Regards yan
the log as following:

192.168.1.2 - - [17/Mar/2020 23:14:45] "POST /socket.io/?EIO=3&transport=polling&t=N3iyo6O&sid=209c1cf8faa045a5ba9f2cb01e259284 HTTP/1.1" 200 -
192.168.1.2 - - [17/Mar/2020 23:14:45] "GET /socket.io/?EIO=3&transport=polling&t=N3iyi09&sid=209c1cf8faa045a5ba9f2cb01e259284 HTTP/1.1" 200 -
Client disconnected 230200cfb6d849ca84223473b944b045
192.168.1.2 - - [17/Mar/2020 23:14:47] "GET /socket.io/?EIO=3&transport=polling&t=N3iyf4j&sid=230200cfb6d849ca84223473b944b045 HTTP/1.1" 200 -

@yanxiaoyan2020 yanxiaoyan2020 changed the title Flask-SocketIO client send disconnect to server Flask-SocketIO auto client send disconnect to server Mar 18, 2020
@miguelgrinberg
Copy link
Owner

I don't understand what the problem is. If the page is closed the connection goes away. The server is not notified of anything, it detects on its own that the client went away.

@yanxiaoyan2020
Copy link
Author

@miguelgrinberg
Maybe I didn't describe this question clearly. The names connect and disconnect are reserved and cannot be used for named events. socketio itself emit 'disconnect' event. I observed that when I close the client(browser,socketio client) or I switch to other page(not socketio client), So the connection goes away when the page(socketio client) is close. this is OK.
My question is that the socketio server (registered disconnect) receives 'disconnect' event when nothing to do with browser(socketio client). I don't know why. the log is caught as following
pi@raspberrypi:~/PROJECT/version0318 $ python3 main.py
main function
WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.

  • Serving Flask app "main" (lazy loading)
  • Environment: production
    WARNING: Do not use the development server in a production environment.
    Use a production WSGI server instead.
  • Debug mode: on
  • Running on http://0.0.0.0:9000/ (Press CTRL+C to quit)
  • Restarting with stat
    main function
    WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
  • Debugger is active!
  • Debugger PIN: 217-227-154
    192.168.1.2 - - [19/Mar/2020 17:35:33] "GET / HTTP/1.1" 200 -
    192.168.1.2 - - [19/Mar/2020 17:35:37] "GET /img HTTP/1.1" 200 -
    camera ini
    mainFire class ini()
    mainfire glovar instance
    192.168.1.2 - - [19/Mar/2020 17:35:38] "GET /socket.io/?EIO=3&transport=polling&t=N3o9yAg HTTP/1.1" 200 -
    server received connect event from client
    background_thread
    192.168.1.2 - - [19/Mar/2020 17:35:38] "POST /socket.io/?EIO=3&transport=polling&t=N3o9yB5&sid=a0ae2a29e3634f09b07fd08ee4f9d3ad HTTP/1.1" 200 -
    192.168.1.2 - - [19/Mar/2020 17:35:38] "GET /socket.io/?EIO=3&transport=polling&t=N3o9yB6&sid=a0ae2a29e3634f09b07fd08ee4f9d3ad HTTP/1.1" 200 -
    getvide finished
    wRecord ini
    display glovar instance
    ini glovar
    <globalvar.glovar object at 0xa9874030>
    192.168.1.2 - - [19/Mar/2020 17:35:40] "GET /socket.io/?EIO=3&transport=polling&t=N3o9yBS&sid=a0ae2a29e3634f09b07fd08ee4f9d3ad HTTP/1.1" 200 -
    192.168.1.2 - - [19/Mar/2020 17:35:42] "GET /socket.io/?EIO=3&transport=polling&t=N3o9ygf&sid=a0ae2a29e3634f09b07fd08ee4f9d3ad HTTP/1.1" 200 -
    gen1
    generator function
    192.168.1.2 - - [19/Mar/2020 17:35:43] "GET /video_feed HTTP/1.1" 200 -
    the network pid:2033; speed:0.005536; the fps:0.000000;time0:1584610546.812285;time3:1584610546.812285;difftime:1584610546.812285;framesum:8772909;
    the network pid:2033; speed:2249683.114232; the fps:25.812987;time0:1584610550.725044;time3:1584610550.725044;difftime:3.912759;framesum:8802468;
    the network pid:2033; speed:2184811.473971; the fps:24.982877;time0:1584610554.767813;time3:1584610554.767813;difftime:4.042769;framesum:8832688;
    the network pid:2033; speed:2189601.543296; the fps:25.034496;time0:1584610558.802246;time3:1584610558.802246;difftime:4.034433;framesum:8833801;
    the network pid:2033; speed:2187049.277674; the fps:25.010915;time0:1584610562.840483;time3:1584610562.840483;difftime:4.038237;framesum:8831823;
    192.168.1.2 - - [19/Mar/2020 17:36:03] "POST /socket.io/?EIO=3&transport=polling&t=N3oA2Hl&sid=a0ae2a29e3634f09b07fd08ee4f9d3ad HTTP/1.1" 200 -
    192.168.1.2 - - [19/Mar/2020 17:36:03] "GET /socket.io/?EIO=3&transport=polling&t=N3o9z9v&sid=a0ae2a29e3634f09b07fd08ee4f9d3ad HTTP/1.1" 200 -
    the network pid:2033; speed:2180744.164522; the fps:24.891383;time0:1584610566.898112;time3:1584610566.898112;difftime:4.057629;framesum:8848651;
    the network pid:2033; speed:2208479.079011; the fps:25.147324;time0:1584610570.914444;time3:1584610570.914444;difftime:4.016332;framesum:8869985;
    the network pid:2033; speed:2186972.770764; the fps:24.975698;time0:1584610574.958375;time3:1584610574.958375;difftime:4.043931;framesum:8843967;
    ...
    the network pid:2033; speed:2284115.542743; the fps:25.023711;time0:1584611069.384079;time3:1584611069.384079;difftime:4.036172;framesum:9219083;
    the network pid:2033; speed:2296696.122475; the fps:24.996504;time0:1584611073.424644;time3:1584611073.424644;difftime:4.040565;framesum:9279950;
    Client disconnected a0ae2a29e3634f09b07fd08ee4f9d3ad
    this discnnected event not emitted by closing page or switched to other page(not socketio client)

    192.168.1.2 - - [19/Mar/2020 17:44:33] "GET /socket.io/?EIO=3&transport=polling&t=N3oBmFB&sid=a0ae2a29e3634f09b07fd08ee4f9d3ad HTTP/1.1" 400 -
    My design is video stream(yield motion-mjpeg) with socketio for pushing information. When the Web stream server setups, user can open browser and watch the video and pushing information.

socketio server as following
main.py
#!/usr/bin/env python
from flask import Flask, render_template, Response,copy_current_request_context,session,request
from flask_socketio import SocketIO,emit,disconnect
from threading import Lock,Thread
#from flask_moment import Moment
from camera import VideoCam
from timeDiff import timeDiff
import time,os

from flask_bootstrap import Bootstrap

PRINT_FLAG = True
PRINT_FLAG1 = False

calctime = timeDiff()
gv = None # fire state :prefire warning fireing
cnnt = False #false disconnect ;True connect
cmr = None # camera instance

async_mode =None

app = Flask(name)
app.config['SECRET_KEY']= 'secret!'
bootstrap = Bootstrap(app)
socketio = SocketIO(app,async_mode=async_mode)

#manager =Manager(app)
#manager.add_command('run', socketio.run(app=app, host='0.0.0.0', port=5000)) # 新加入的
thread =None
thread_lock =Lock()

def background_thread():
print("background_thread")
count = 0
global gv

while True:

    socketio.sleep(1)

    count +=1
    #print(gv)
    socketio.sleep(1)
    if gv ==None:
        socketio.emit('my_response', {'data': 'fire state not,server send msg to client', 'count': count}, namespace='/test')
        #print("fire state not data")
        continue
    else:
        pass
        #print("fire state has data")
    fw = gv.getstate()
    #print("fire state:%s;fire value:%d" %(fw['state'],fw['value']))

    if fw['state'] !='normal':

        value = fw['value']
        num = fw['state']
        socketio.emit('my_response',{'data':num,'count':value},namespace='/test')

@socketio.on('connect',namespace='/test')
def test_connect():
global cnnt
print("server received connect event from client")
global thread
with thread_lock:
if thread is None:
thread = socketio.start_background_task(background_thread)
emit('my_response',{'data':'socketIO connected','count':0})
cnnt = True

@socketio.on('disconnect_request', namespace='/test')
def disconnect_request():
global cnnt
@copy_current_request_context
def can_disconnect():
disconnect()
pass

session['receive_count'] = session.get('receive_count', 0) + 1
# for this emit we use a callback function
# when the callback function is invoked we know that the message has been
# received and it is safe to disconnect
emit('my_response',
     {'data': 'Disconnected!', 'count': session['receive_count']},
     callback=can_disconnect)
cnnt = False
print("receivde stop play message from client,play state:%d" %cnnt)

@socketio.on('disconnect', namespace='/test')
def test_disconnect():
global cnnt
print('Client disconnected', request.sid)
cnnt = False

emit('my_response',{'data':'socketIO disconnected','count':0})

@socketio.on('my_event', namespace='/test')
def test_message(message):

session['receive_count'] = session.get('receive_count', 0) + 1
emit('my_response',
     {'data':  message['data'], 'count': session['receive_count']})

@app.route('/img')
def img():
#return render_template('index.html',current_time=datetime.datetime.utcnow())
return render_template('index.html',async_mode=socketio.async_mode)
#return render_template('product1.html', async_mode=socketio.async_mode)

@app.route('/')
def index():
#return render_template('index.html',current_time=datetime.datetime.utcnow())
return render_template('product1.html',async_mode=socketio.async_mode)

@app.route('/video_feed')
def video_feed():
global cnnt,cmr

cnnt = True
if cmr!= None:

    return Response(gen(cmr),mimetype='multipart/x-mixed-replace; boundary=frame')
else:
    return Response(gen(VideoCam()),mimetype='multipart/x-mixed-replace; boundary=frame')

def gen(camera):
print("gen1")
global socketio,cnnt,gv,cmr
cmr = camera
if PRINT_FLAG:
print("generator function")
framesum = 0
time0 = 0
framecount=0
frame = None

while True:
    try:
        time.sleep(0.001)
        if PRINT_FLAG1:
            time1 = calctime.calctime()
        ret ,frame,gt = camera.get_frame()
        gv = gt

        if cnnt ==False:
            continue

        if ret:

            yield (b'--frame\r\n'
                b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
           

            if PRINT_FLAG:
                framesum = framesum + len(frame)
                framecount = framecount+1

                if framecount>100:

                    if PRINT_FLAG:
                        time3 = calctime.calctime()
                        diff=calctime.diffTime(4,time0,time3)
                        time0 = time3
                        speed = framesum/diff
                        fps = framecount/diff

                        print("the network pid:%d; speed:%f; the fps:%f;time0:%f;time3:%f;difftime:%f;framesum:%d;" %(os.getpid(),speed,fps,time0,time3,diff,framesum))
                        framesum = 0
                        framecount = 0
        else:
            if PRINT_FLAG:
                print("the web thread sleep 0.1")
            continue

    except Exception as err:
        print("main web get frame error :%s" %err)
    finally:

        if PRINT_FLAG1:
            print("web received and send one frame ")

if name == 'main':

cmr = VideoCam()

socketio.run(app,debug =True,host='0.0.0.0',port=9000)

socketio client
xtends "base.html" %}

{% block title %}
<title>youhang platform</title>
<script src="//code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js" integrity="sha256-yr4fRk/GU1ehYJPAs8P4JlTgu0Hdsp4ZKrx8bDEDC3I=" crossorigin="anonymous"></script>
<script type="text/javascript" charset="utf-8">

    $(document).ready(function() {
        // Use a "/test" namespace.
        // An application can open a connection on multiple namespaces, and
        // Socket.IO will multiplex all those connections on a single
        // physical channel. If you don't care about multiple channels, you
        // can set the namespace to an empty string.
        namespace = '/test';

        // Connect to the Socket.IO server.
        // The connection URL has the following format, relative to the current page:
        //     http[s]://<domain>:<port>[/<namespace>]
        var socket = io(namespace);

        // Event handler for new connections.
        // The callback function is invoked when a connection with the
        // server is established.
        socket.on('connect', function() {
            ;
            //socket.emit('my_event', {data: 'I\'m connected!'});
        });
        // Event handler for server sent data.
        // The callback function is invoked whenever the server emits data
        // to the client. The data is then displayed in the "Received"
        // section of the page.
        ///*
        socket.on('my_response', function(msg, cb) {
            $('#stat').text('status #' + msg.count + ': ' + msg.data);
            if (cb)
                cb();
        });
        //*/
        /*
         socket.on('my_response', function(msg, cb) {
            $('#log').append('<br>' + $('<div/>').text('Received #' + msg.count + ': ' + msg.data).html());
            if (cb)
                cb();
        });
        */
        // Handlers for the different forms in the page.
        // These accept data from the user and send it to the server in a
        // variety of ways
        $('form#emt').submit(function(event) {
            socket.emit('my_event',{data: 'I\'m message!'});
            return false;
        });

         $('form#disconnect').submit(function(event) {
            socket.emit('disconnect_request');
            return false;
        });


      });
   </script>

{% endblock %}

{% block page_content %}

fire detect!

Receive:

not connect

centered image

{% endblock %}
beside ,I install and try eventlet(gevent,gevent-websocket), one of processes can not setup,and sometime the socketio doesn't work. I don't know whether this is cause or not.

looking forward your response
Best regards yan

@miguelgrinberg
Copy link
Owner

You haven't enabled Socket.IO logs so I can't really say for sure.

The server will declare clients as disconnected if they fail to send the required ping packets at the correct interval. What I've seen sometimes happening is that even when the client sends the pings correctly, if the server is extremely busy or blocked it will not process those pings timely, and will also consider clients as gone. Any chance your server is doing too much work and cannot tend to clients in a timely manner?

@yanxiaoyan2020
Copy link
Author

yanxiaoyan2020 commented Mar 19, 2020

@miguelgrinberg
Maybe your analysis is possible. When I test this case in win OS , the web server always receives 'disconnect' event firstly,then receives 'connect' event. But When I test this case in raspberry pi, the web server first receives 'connect' event. then receives 'disconnect' event .

 I remember details.This case is that I select the browser(socketio client page) that is playing live stream video,then click enter,that is refreshing the browser(socketio client page) by hand

Would you please tell me how to enable Socket.IO . I want to catch logs again for you. 

 If ‘disconnet’ event is sent after 'connect' event refreshing brower(socketio client) .the Control of stream video doest not work. So I neet to resolve this question.

 Thanks for you to take time to answer this question ,It's nice of you
  Best Regard Yan

@miguelgrinberg
Copy link
Owner

Logs
Please provide relevant logs from the server and the client. On the server, add the logger=True and engineio_logger=True arguments to your SocketIO() object to get logs dumped on your terminal. The same arguments can be used on the python-socketio's client. If you are using the JavaScript client, see here for how to enable logs.

@yanxiaoyan2020
Copy link
Author

yanxiaoyan2020 commented Mar 20, 2020

@miguelgrinberg

this log was caught in win OS

Server initialized for gevent.
 * Restarting with stat
Server initialized for gevent.
 * Debugger is active!
 * Debugger PIN: 275-213-182
camera ini
mainFire class ini()
mainfire glovar instance
Server initialized for gevent.
getvide finished
Server initialized for gevent.
577608098e644059ba76f81765793d42: Sending packet OPEN data {'sid': '577608098e644059ba76f81765793d42', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}
577608098e644059ba76f81765793d42: Sending packet MESSAGE data 0
wRecord ini
display glovar instance
ini glovar
<globalvar.glovar object at 0x0000028E7FAF1B70>
577608098e644059ba76f81765793d42: Received packet MESSAGE data 0/test,
the web server receives 'connect'  event(registered by server)  577608098e644059ba76f81765793d42
emitting event "my_response" to 577608098e644059ba76f81765793d42 [/test]
577608098e644059ba76f81765793d42: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
577608098e644059ba76f81765793d42: Sending packet MESSAGE data 0/test
background_thread
577608098e644059ba76f81765793d42: Received request to upgrade to websocket
577608098e644059ba76f81765793d42: Upgrade to websocket successful
Server initialized for gevent.
gen1
generator function
emitting event "my_response" to all [/test]
577608098e644059ba76f81765793d42: Sending packet MESSAGE data 2/test,["my_response",{"data":"prewarning","count":60}]
emitting event "my_response" to all [/test]
577608098e644059ba76f81765793d42: Sending packet MESSAGE data 2/test,["my_response",{"data":"prewarning","count":60}]
emitting event "my_response" to all [/test]
577608098e644059ba76f81765793d42: Sending packet MESSAGE data 2/test,["my_response",{"data":"warning","count":70}]
gen1
generator function
the web server receive  'disconnected' event(registered by server)  577608098e644059ba76f81765793d42
emitting event "my_response" to 577608098e644059ba76f81765793d42 [/test]
577608098e644059ba76f81765793d42: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO disconnected","count":0}]
e05e574b9683446e888e0aa4b5176d38: Sending packet OPEN data {'sid': 'e05e574b9683446e888e0aa4b5176d38', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}
e05e574b9683446e888e0aa4b5176d38: Sending packet MESSAGE data 0
e05e574b9683446e888e0aa4b5176d38: Received packet MESSAGE data 0/test,
the web server receives 'connect'  event(registered by server)  e05e574b9683446e888e0aa4b5176d38
emitting event "my_response" to e05e574b9683446e888e0aa4b5176d38 [/test]
e05e574b9683446e888e0aa4b5176d38: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
e05e574b9683446e888e0aa4b5176d38: Sending packet MESSAGE data 0/test
e05e574b9683446e888e0aa4b5176d38: Received request to upgrade to websocket
e05e574b9683446e888e0aa4b5176d38: Upgrade to websocket successful
emitting event "my_response" to all [/test]
e05e574b9683446e888e0aa4b5176d38: Sending packet MESSAGE data 2/test,["my_response",{"data":"warning","count":70}]
emitting event "my_response" to all [/test]
e05e574b9683446e888e0aa4b5176d38: Sending packet MESSAGE data 2/test,["my_response",{"data":"warning","count":70}]
<globalvar.glovar object at 0x0000028E7FAF1B70>
gvar state:warning; fire value:70
emitting event "my_response" to all [/test]
e05e574b9683446e888e0aa4b5176d38: Sending packet MESSAGE data 2/test,["my_response",{"data":"fireing","count":80}]
emitting event "my_response" to all [/test]
e05e574b9683446e888e0aa4b5176d38: Sending packet MESSAGE data 2/test,["my_response",{"data":"fireing","count":80}]

This log was caught in raspberrypi 4B(debian OS)

### note:
1 192.168.1.2 - - [20/Mar/2020 10:40:02] "GET /img HTTP/1.1" 200 #I select and refresh browser(socketIO client)
2 the web server receives 'connect' event(registered by server) added by me when the web server receive ‘connect’ event. the web server receives 'disconnect'event(registered by server) too.
3 the web server received 'connect' event,after about 25s received 'disconnect' event.
4 I observed that disconnect event session sid is old and the connect event sid is new. They are difference,So I utilize this to resolve first connect event second disconnect evetn in raspberrypi debian os ,and the control of video stream playing can work. thank your clue.

pi@raspberrypi:~/PROJECT/version0318 $ python3 main.py
Server initialized for threading.
main function
WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
 * Serving Flask app "main" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:9000/ (Press CTRL+C to quit)
 * Restarting with stat
Server initialized for threading.
main function
WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
 * Debugger is active!
 * Debugger PIN: 217-227-154
97705dcc1f444349aeb67525dd511c8b: Sending packet OPEN data {'sid': '97705dcc1f444349aeb67525dd511c8b', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}
97705dcc1f444349aeb67525dd511c8b: Sending packet MESSAGE data 0
192.168.1.2 - - [20/Mar/2020 10:39:31] "GET /socket.io/?EIO=3&transport=polling&t=N3rqI76 HTTP/1.1" 200 -
97705dcc1f444349aeb67525dd511c8b: Received packet MESSAGE data 0/test,
the web server receives 'connect' event(registered by server) 97705dcc1f444349aeb67525dd511c8b
background_thread
emitting event "my_response" to 97705dcc1f444349aeb67525dd511c8b [/test]
97705dcc1f444349aeb67525dd511c8b: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
97705dcc1f444349aeb67525dd511c8b: Sending packet MESSAGE data 0/test
192.168.1.2 - - [20/Mar/2020 10:39:31] "POST /socket.io/?EIO=3&transport=polling&t=N3rqIg-&sid=97705dcc1f444349aeb67525dd511c8b HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 10:39:31] "GET /socket.io/?EIO=3&transport=polling&t=N3rqIg_&sid=97705dcc1f444349aeb67525dd511c8b HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 10:39:37] "GET / HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 10:39:43] "GET /img HTTP/1.1" 200 -
camera ini
mainFire class ini()
mainfire glovar instance
85fa42a15b584616bb64d33fad6aaefa: Sending packet OPEN data {'sid': '85fa42a15b584616bb64d33fad6aaefa', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}
85fa42a15b584616bb64d33fad6aaefa: Sending packet MESSAGE data 0
192.168.1.2 - - [20/Mar/2020 10:39:43] "GET /socket.io/?EIO=3&transport=polling&t=N3rqLgD HTTP/1.1" 200 -
85fa42a15b584616bb64d33fad6aaefa: Received packet MESSAGE data 0/test,
the web server receives 'connect' event(registered by server) 85fa42a15b584616bb64d33fad6aaefa
emitting event "my_response" to 85fa42a15b584616bb64d33fad6aaefa [/test]
85fa42a15b584616bb64d33fad6aaefa: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
85fa42a15b584616bb64d33fad6aaefa: Sending packet MESSAGE data 0/test
192.168.1.2 - - [20/Mar/2020 10:39:43] "POST /socket.io/?EIO=3&transport=polling&t=N3rqLgT&sid=85fa42a15b584616bb64d33fad6aaefa HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 10:39:43] "GET /socket.io/?EIO=3&transport=polling&t=N3rqLgT.0&sid=85fa42a15b584616bb64d33fad6aaefa HTTP/1.1" 200 -
getvide finished
wRecord ini
display glovar instance
ini glovar
<globalvar.glovar object at 0xa98ed910>
gen1
generator function
192.168.1.2 - - [20/Mar/2020 10:39:49] "GET /video_feed HTTP/1.1" 200 -
the network pid:1322; speed:0.005246; the fps:0.000000;time0:1584671992.537175;time3:1584671992.537175;difftime:1584671992.537175;framesum:8313654;
the network pid:1322; speed:1982909.329178; the fps:25.003651;time0:1584671996.576585;time3:1584671996.576585;difftime:4.039410;framesum:8009784;
the network pid:1322; speed:2017720.524571; the fps:25.020635;time0:1584672000.613253;time3:1584672000.613253;difftime:4.036668;framesum:8144868;
192.168.1.2 - - [20/Mar/2020 10:40:02] "GET /img HTTP/1.1" 200 -
gen1
generator function
805608d1144e4772b06de6400027f53a: Sending packet OPEN data {'sid': '805608d1144e4772b06de6400027f53a', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}
805608d1144e4772b06de6400027f53a: Sending packet MESSAGE data 0
192.168.1.2 - - [20/Mar/2020 10:40:02] "GET /socket.io/?EIO=3&transport=polling&t=N3rqQE0 HTTP/1.1" 200 -
805608d1144e4772b06de6400027f53a: Received packet MESSAGE data 0/test,
the web server receives 'connect' event(registered by server) 805608d1144e4772b06de6400027f53a
192.168.1.2 - - [20/Mar/2020 10:40:02] "GET /video_feed HTTP/1.1" 200 -
emitting event "my_response" to 805608d1144e4772b06de6400027f53a [/test]
805608d1144e4772b06de6400027f53a: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
805608d1144e4772b06de6400027f53a: Sending packet MESSAGE data 0/test
192.168.1.2 - - [20/Mar/2020 10:40:02] "POST /socket.io/?EIO=3&transport=polling&t=N3rqQEJ&sid=805608d1144e4772b06de6400027f53a HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 10:40:02] "GET /socket.io/?EIO=3&transport=polling&t=N3rqQEK&sid=805608d1144e4772b06de6400027f53a HTTP/1.1" 200 -
the network pid:1322; speed:0.005343; the fps:0.000000;time0:1584672006.486296;time3:1584672006.486296;difftime:1584672006.486296;framesum:8466376;
the network pid:1322; speed:2107509.539227; the fps:25.025093;time0:1584672010.522245;time3:1584672010.522245;difftime:4.035949;framesum:8505801;
the network pid:1322; speed:2107047.597148; the fps:25.017029;time0:1584672014.559495;time3:1584672014.559495;difftime:4.037250;framesum:8506678;
the network pid:1322; speed:2006675.343475; the fps:24.999295;time0:1584672018.599609;time3:1584672018.599609;difftime:4.040114;framesum:8107197;
the network pid:1322; speed:2051921.283112; the fps:25.011100;time0:1584672022.637816;time3:1584672022.637816;difftime:4.038207;framesum:8286083;
the network pid:1322; speed:2042144.544779; the fps:24.912964;time0:1584672026.691930;time3:1584672026.691930;difftime:4.054114;framesum:8279087;
805608d1144e4772b06de6400027f53a: Received packet PING data None
805608d1144e4772b06de6400027f53a: Sending packet PONG data None
192.168.1.2 - - [20/Mar/2020 10:40:27] "POST /socket.io/?EIO=3&transport=polling&t=N3rqWKy&sid=805608d1144e4772b06de6400027f53a HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 10:40:27] "GET /socket.io/?EIO=3&transport=polling&t=N3rqQEm&sid=805608d1144e4772b06de6400027f53a HTTP/1.1" 200 -
the network pid:1322; speed:2073232.279747; the fps:25.120923;time0:1584672030.712483;time3:1584672030.712483;difftime:4.020553;framesum:8335540;
the web server receives 'disconnect'event(registered by server) 97705dcc1f444349aeb67525dd511c8b
emitting event "my_response" to 97705dcc1f444349aeb67525dd511c8b [/test]
97705dcc1f444349aeb67525dd511c8b: Client is gone, closing socket
97705dcc1f444349aeb67525dd511c8b: Client is gone, closing socket
192.168.1.2 - - [20/Mar/2020 10:40:31] "GET /socket.io/?EIO=3&transport=polling&t=N3rqIhO&sid=97705dcc1f444349aeb67525dd511c8b HTTP/1.1" 400 -
85fa42a15b584616bb64d33fad6aaefa: Client is gone, closing socket
the web server receives 'disconnect'event(registered by server) 85fa42a15b584616bb64d33fad6aaefa
emitting event "my_response" to 85fa42a15b584616bb64d33fad6aaefa [/test]
85fa42a15b584616bb64d33fad6aaefa: Client is gone, closing socket
85fa42a15b584616bb64d33fad6aaefa: Client is gone, closing socket
192.168.1.2 - - [20/Mar/2020 10:40:31] "GET /socket.io/?EIO=3&transport=polling&t=N3rqLgi&sid=85fa42a15b584616bb64d33fad6aaefa HTTP/1.1" 200 -
805608d1144e4772b06de6400027f53a: Received packet PING data None
805608d1144e4772b06de6400027f53a: Sending packet PONG data None
192.168.1.2 - - [20/Mar/2020 10:40:52] "GET /socket.io/?EIO=3&transport=polling&t=N3rqWL7&sid=805608d1144e4772b06de6400027f53a HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 10:40:52] "POST /socket.io/?EIO=3&transport=polling&t=N3rqcRm&sid=805608d1144e4772b06de6400027f53a HTTP/1.1" 200 -

this log was caught when I changed code

pi@raspberrypi:~/PROJECT/version0318 $ python3 main.py
Server initialized for threading.
main function
WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
 * Serving Flask app "main" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:9000/ (Press CTRL+C to quit)
 * Restarting with stat
Server initialized for threading.
main function
WebSocket transport not available. Install eventlet or gevent and gevent-websocket for improved performance.
 * Debugger is active!
 * Debugger PIN: 217-227-154
cb5ce536a8764c949e2a1323a8b8e031: Sending packet OPEN data {'sid': 'cb5ce536a8764c949e2a1323a8b8e031', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}
cb5ce536a8764c949e2a1323a8b8e031: Sending packet MESSAGE data 0
192.168.1.2 - - [20/Mar/2020 11:28:58] "GET /socket.io/?EIO=3&transport=polling&t=N3s0lLT HTTP/1.1" 200 -
cb5ce536a8764c949e2a1323a8b8e031: Received packet MESSAGE data 0/test,
the web server receives 'connect' event(registered by server) cb5ce536a8764c949e2a1323a8b8e031
background_thread
emitting event "my_response" to cb5ce536a8764c949e2a1323a8b8e031 [/test]
cb5ce536a8764c949e2a1323a8b8e031: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
cb5ce536a8764c949e2a1323a8b8e031: Sending packet MESSAGE data 0/test
192.168.1.2 - - [20/Mar/2020 11:28:58] "POST /socket.io/?EIO=3&transport=polling&t=N3s0lRG&sid=cb5ce536a8764c949e2a1323a8b8e031 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:28:58] "GET /socket.io/?EIO=3&transport=polling&t=N3s0lRG.0&sid=cb5ce536a8764c949e2a1323a8b8e031 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:29:12] "GET /img HTTP/1.1" 200 -
camera ini
mainFire class ini()
mainfire glovar instance
f9223f039eb1401281b54107dc064254: Sending packet OPEN data {'sid': 'f9223f039eb1401281b54107dc064254', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}
f9223f039eb1401281b54107dc064254: Sending packet MESSAGE data 0
192.168.1.2 - - [20/Mar/2020 11:29:12] "GET /socket.io/?EIO=3&transport=polling&t=N3s0ox2 HTTP/1.1" 200 -
f9223f039eb1401281b54107dc064254: Received packet MESSAGE data 0/test,
the web server receives 'connect' event(registered by server) f9223f039eb1401281b54107dc064254
emitting event "my_response" to f9223f039eb1401281b54107dc064254 [/test]
f9223f039eb1401281b54107dc064254: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
f9223f039eb1401281b54107dc064254: Sending packet MESSAGE data 0/test
192.168.1.2 - - [20/Mar/2020 11:29:12] "POST /socket.io/?EIO=3&transport=polling&t=N3s0oxH&sid=f9223f039eb1401281b54107dc064254 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:29:12] "GET /socket.io/?EIO=3&transport=polling&t=N3s0oxH.0&sid=f9223f039eb1401281b54107dc064254 HTTP/1.1" 200 -
getvide finished
wRecord ini
display glovar instance
ini glovar
<globalvar.glovar object at 0xa98ab650>
gen1
192.168.1.2 - - [20/Mar/2020 11:29:18] "GET /video_feed HTTP/1.1" 200 -
f9223f039eb1401281b54107dc064254: Received packet PING data None
f9223f039eb1401281b54107dc064254: Sending packet PONG data None
192.168.1.2 - - [20/Mar/2020 11:29:37] "GET /socket.io/?EIO=3&transport=polling&t=N3s0oxW&sid=f9223f039eb1401281b54107dc064254 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:29:37] "POST /socket.io/?EIO=3&transport=polling&t=N3s0v1w&sid=f9223f039eb1401281b54107dc064254 HTTP/1.1" 200 -
the web server receives 'disconnect'event(registered by server) cb5ce536a8764c949e2a1323a8b8e031
the current session sid:f9223f039eb1401281b54107dc064254;the old session sid:cb5ce536a8764c949e2a1323a8b8e031
emitting event "my_response" to cb5ce536a8764c949e2a1323a8b8e031 [/test]
cb5ce536a8764c949e2a1323a8b8e031: Client is gone, closing socket
cb5ce536a8764c949e2a1323a8b8e031: Client is gone, closing socket
192.168.1.2 - - [20/Mar/2020 11:29:58] "GET /socket.io/?EIO=3&transport=polling&t=N3s0lRU&sid=cb5ce536a8764c949e2a1323a8b8e031 HTTP/1.1" 400 -
f9223f039eb1401281b54107dc064254: Received packet PING data None
f9223f039eb1401281b54107dc064254: Sending packet PONG data None
192.168.1.2 - - [20/Mar/2020 11:30:03] "GET /socket.io/?EIO=3&transport=polling&t=N3s0v2D&sid=f9223f039eb1401281b54107dc064254 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:30:03] "POST /socket.io/?EIO=3&transport=polling&t=N3s0_8t&sid=f9223f039eb1401281b54107dc064254 HTTP/1.1" 200 -
f9223f039eb1401281b54107dc064254: Received packet PING data None
f9223f039eb1401281b54107dc064254: Sending packet PONG data None
192.168.1.2 - - [20/Mar/2020 11:30:28] "GET /socket.io/?EIO=3&transport=polling&t=N3s0_91&sid=f9223f039eb1401281b54107dc064254 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:30:28] "POST /socket.io/?EIO=3&transport=polling&t=N3s15Fg&sid=f9223f039eb1401281b54107dc064254 HTTP/1.1" 200 -
f9223f039eb1401281b54107dc064254: Received packet PING data None
f9223f039eb1401281b54107dc064254: Sending packet PONG data None
192.168.1.2 - - [20/Mar/2020 11:30:53] "POST /socket.io/?EIO=3&transport=polling&t=N3s1BMS&sid=f9223f039eb1401281b54107dc064254 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:30:53] "GET /socket.io/?EIO=3&transport=polling&t=N3s15Fp&sid=f9223f039eb1401281b54107dc064254 HTTP/1.1" 200 -
f9223f039eb1401281b54107dc064254: Received packet PING data None
f9223f039eb1401281b54107dc064254: Sending packet PONG data None
192.168.1.2 - - [20/Mar/2020 11:31:18] "GET /socket.io/?EIO=3&transport=polling&t=N3s1BMx&sid=f9223f039eb1401281b54107dc064254 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:31:18] "POST /socket.io/?EIO=3&transport=polling&t=N3s1HTk&sid=f9223f039eb1401281b54107dc064254 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:31:26] "GET /img HTTP/1.1" 200 -
gen1
9c60cc4298544ab0bf6b54d36f26b898: Sending packet OPEN data {'sid': '9c60cc4298544ab0bf6b54d36f26b898', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}
9c60cc4298544ab0bf6b54d36f26b898: Sending packet MESSAGE data 0
192.168.1.2 - - [20/Mar/2020 11:31:27] "GET /socket.io/?EIO=3&transport=polling&t=N3s1Jg0 HTTP/1.1" 200 -
9c60cc4298544ab0bf6b54d36f26b898: Received packet MESSAGE data 0/test,
the web server receives 'connect' event(registered by server) 9c60cc4298544ab0bf6b54d36f26b898
emitting event "my_response" to 9c60cc4298544ab0bf6b54d36f26b898 [/test]
9c60cc4298544ab0bf6b54d36f26b898: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
9c60cc4298544ab0bf6b54d36f26b898: Sending packet MESSAGE data 0/test
192.168.1.2 - - [20/Mar/2020 11:31:27] "POST /socket.io/?EIO=3&transport=polling&t=N3s1JgD&sid=9c60cc4298544ab0bf6b54d36f26b898 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:31:27] "GET /socket.io/?EIO=3&transport=polling&t=N3s1JgD.0&sid=9c60cc4298544ab0bf6b54d36f26b898 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:31:27] "GET /video_feed HTTP/1.1" 200 -
9c60cc4298544ab0bf6b54d36f26b898: Received packet PING data None
9c60cc4298544ab0bf6b54d36f26b898: Sending packet PONG data None
192.168.1.2 - - [20/Mar/2020 11:31:52] "GET /socket.io/?EIO=3&transport=polling&t=N3s1Jgl&sid=9c60cc4298544ab0bf6b54d36f26b898 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:31:52] "POST /socket.io/?EIO=3&transport=polling&t=N3s1Pms&sid=9c60cc4298544ab0bf6b54d36f26b898 HTTP/1.1" 200 -
f9223f039eb1401281b54107dc064254: Client is gone, closing socket
the web server receives 'disconnect'event(registered by server) f9223f039eb1401281b54107dc064254
the current session sid:9c60cc4298544ab0bf6b54d36f26b898;the old session sid:f9223f039eb1401281b54107dc064254
emitting event "my_response" to f9223f039eb1401281b54107dc064254 [/test]
f9223f039eb1401281b54107dc064254: Client is gone, closing socket
f9223f039eb1401281b54107dc064254: Client is gone, closing socket
192.168.1.2 - - [20/Mar/2020 11:31:58] "GET /socket.io/?EIO=3&transport=polling&t=N3s1HUX&sid=f9223f039eb1401281b54107dc064254 HTTP/1.1" 200 -
9c60cc4298544ab0bf6b54d36f26b898: Received packet PING data None
9c60cc4298544ab0bf6b54d36f26b898: Sending packet PONG data None
192.168.1.2 - - [20/Mar/2020 11:32:17] "GET /socket.io/?EIO=3&transport=polling&t=N3s1PnP&sid=9c60cc4298544ab0bf6b54d36f26b898 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:32:17] "POST /socket.io/?EIO=3&transport=polling&t=N3s1Vu1&sid=9c60cc4298544ab0bf6b54d36f26b898 HTTP/1.1" 200 -
9c60cc4298544ab0bf6b54d36f26b898: Received packet PING data None
9c60cc4298544ab0bf6b54d36f26b898: Sending packet PONG data None
192.168.1.2 - - [20/Mar/2020 11:32:42] "GET /socket.io/?EIO=3&transport=polling&t=N3s1VuN&sid=9c60cc4298544ab0bf6b54d36f26b898 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:32:42] "POST /socket.io/?EIO=3&transport=polling&t=N3s1b_0&sid=9c60cc4298544ab0bf6b54d36f26b898 HTTP/1.1" 200 -
9c60cc4298544ab0bf6b54d36f26b898: Received packet PING data None
9c60cc4298544ab0bf6b54d36f26b898: Sending packet PONG data None
192.168.1.2 - - [20/Mar/2020 11:33:07] "POST /socket.io/?EIO=3&transport=polling&t=N3s1i5_&sid=9c60cc4298544ab0bf6b54d36f26b898 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:33:07] "GET /socket.io/?EIO=3&transport=polling&t=N3s1b_M&sid=9c60cc4298544ab0bf6b54d36f26b898 HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:33:18] "GET /img HTTP/1.1" 200 -
gen1
55dd1980b690477a99b10bbbb01c458e: Sending packet OPEN data {'sid': '55dd1980b690477a99b10bbbb01c458e', 'upgrades': [], 'pingTimeout': 60000, 'pingInterval': 25000}
55dd1980b690477a99b10bbbb01c458e: Sending packet MESSAGE data 0
192.168.1.2 - - [20/Mar/2020 11:33:18] "GET /socket.io/?EIO=3&transport=polling&t=N3s1kwm HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:33:18] "GET /video_feed HTTP/1.1" 200 -
55dd1980b690477a99b10bbbb01c458e: Received packet MESSAGE data 0/test,
the web server receives 'connect' event(registered by server) 55dd1980b690477a99b10bbbb01c458e
emitting event "my_response" to 55dd1980b690477a99b10bbbb01c458e [/test]
55dd1980b690477a99b10bbbb01c458e: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
55dd1980b690477a99b10bbbb01c458e: Sending packet MESSAGE data 0/test
192.168.1.2 - - [20/Mar/2020 11:33:18] "POST /socket.io/?EIO=3&transport=polling&t=N3s1kxL&sid=55dd1980b690477a99b10bbbb01c458e HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:33:18] "GET /socket.io/?EIO=3&transport=polling&t=N3s1kxM&sid=55dd1980b690477a99b10bbbb01c458e HTTP/1.1" 200 -
55dd1980b690477a99b10bbbb01c458e: Received packet PING data None
55dd1980b690477a99b10bbbb01c458e: Sending packet PONG data None
192.168.1.2 - - [20/Mar/2020 11:33:43] "GET /socket.io/?EIO=3&transport=polling&t=N3s1kxq&sid=55dd1980b690477a99b10bbbb01c458e HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:33:43] "POST /socket.io/?EIO=3&transport=polling&t=N3s1r1-&sid=55dd1980b690477a99b10bbbb01c458e HTTP/1.1" 200 -
9c60cc4298544ab0bf6b54d36f26b898: Client is gone, closing socket
the web server receives 'disconnect'event(registered by server) 9c60cc4298544ab0bf6b54d36f26b898
the current session sid:55dd1980b690477a99b10bbbb01c458e;the old session sid:9c60cc4298544ab0bf6b54d36f26b898
emitting event "my_response" to 9c60cc4298544ab0bf6b54d36f26b898 [/test]
9c60cc4298544ab0bf6b54d36f26b898: Client is gone, closing socket
9c60cc4298544ab0bf6b54d36f26b898: Client is gone, closing socket
192.168.1.2 - - [20/Mar/2020 11:33:58] "GET /socket.io/?EIO=3&transport=polling&t=N3s1i6C&sid=9c60cc4298544ab0bf6b54d36f26b898 HTTP/1.1" 200 -
55dd1980b690477a99b10bbbb01c458e: Received packet PING data None
55dd1980b690477a99b10bbbb01c458e: Sending packet PONG data None
192.168.1.2 - - [20/Mar/2020 11:34:08] "POST /socket.io/?EIO=3&transport=polling&t=N3s1x95&sid=55dd1980b690477a99b10bbbb01c458e HTTP/1.1" 200 -
192.168.1.2 - - [20/Mar/2020 11:34:08] "GET /socket.io/?EIO=3&transport=polling&t=N3s1r2R&sid=55dd1980b690477a99b10bbbb01c458e HTTP/1.1" 200 -
55dd1980b690477a99b10bbbb01c458e: Received packet PING data None
55dd1980b690477a99b10bbbb01c458e: Sending packet PONG data None

I really appreciate your help. It's importent for me to give me some suggestion and analysis.
It's nice of you to take time to answer these questions. Thank you again
Best Regards Yan

@miguelgrinberg
Copy link
Owner

Are you refreshing the page on the browser? That would cause the current connection to be broken and you will receive a disconnect. The new page will make a new connection.

If you were using WebSocket, on a page refresh you would see a disconnect for the old sid, followed by a connect event for the new sid.

But you are using long-polling, so disconnects are detected after about a minute. So at the time of the page refresh you will get a connect for the new sid, and a minute or so later you will receive the disconnect for the old sid.

@yanxiaoyan2020
Copy link
Author

yanxiaoyan2020 commented Mar 20, 2020 via email

@yanxiaoyan2020
Copy link
Author

@miguelgrinberg
I tested three cases with eventlet,gevent and uninstalling both of them in raspberry debian OS.
1、The logs was caught using gevent(only installing gevent) as below in raspberry debian OS with infra camera and video camera.
I have already test this gevent replacing infra camera and video camera with coressponding files in raspberry debian os . It doesn't work too,So I think this issue not because of hardware.
But in fact I test this case using gevent on win OS with video fire as video input .It works well
How can I resove it with gevent as web server?
Server initialized for gevent.
main function

  • Restarting with stat
    Server initialized for gevent.
    main function
  • Debugger is active!
  • Debugger PIN: 217-924-079
    1904ca3f473c4c558dde2f17638ffad6: Sending packet OPEN data {'sid': '1904ca3f473c4c558dde2f17638ffad6', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}
    1904ca3f473c4c558dde2f17638ffad6: Sending packet MESSAGE data 0
    1904ca3f473c4c558dde2f17638ffad6: Received packet MESSAGE data 0/test,
    the web server receives 'connect' event(registered by server) 1904ca3f473c4c558dde2f17638ffad6
    emitting event "my_response" to 1904ca3f473c4c558dde2f17638ffad6 [/test]
    1904ca3f473c4c558dde2f17638ffad6: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
    1904ca3f473c4c558dde2f17638ffad6: Sending packet MESSAGE data 0/test
    background_thread
    1904ca3f473c4c558dde2f17638ffad6: Received request to upgrade to websocket
    1904ca3f473c4c558dde2f17638ffad6: Upgrade to websocket successful
    the web server receives 'disconnect'event(registered by server) 1904ca3f473c4c558dde2f17638ffad6
    emitting event "my_response" to 1904ca3f473c4c558dde2f17638ffad6 [/test]
    1904ca3f473c4c558dde2f17638ffad6: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO disconnected","count":0}]
    camera ini
    mainFire class ini()
    mainfire glovar instance
    16ea84e8c3634dddb1792ab46e570edb: Sending packet OPEN data {'sid': '16ea84e8c3634dddb1792ab46e570edb', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}
    16ea84e8c3634dddb1792ab46e570edb: Sending packet MESSAGE data 0
    16ea84e8c3634dddb1792ab46e570edb: Received packet MESSAGE data 0/test,
    the web server receives 'connect' event(registered by server) 16ea84e8c3634dddb1792ab46e570edb
    emitting event "my_response" to 16ea84e8c3634dddb1792ab46e570edb [/test]
    16ea84e8c3634dddb1792ab46e570edb: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
    16ea84e8c3634dddb1792ab46e570edb: Sending packet MESSAGE data 0/test
    16ea84e8c3634dddb1792ab46e570edb: Received request to upgrade to websocket
    getVide process ini()
    getVide thread get common frame from camera
    get FPS:30
    set FPS:10,set successfully
    get again FPS:25
    getvide finished
    getVide thread getdata()
    16ea84e8c3634dddb1792ab46e570edb: Upgrade to websocket successful
    getVide thread get the first common frame successfully
    dispFire class ini()
    wRecord ini
    display glovar instance
    ini glovar
    <globalvar.glovar object at 0xa9b68b90>
    finished ini
    gen1
    None
    generator function
    True
    before get frame
    ^CProcess getVido:
    Process dectFire:
    Traceback (most recent call last):
    File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
    File "/home/pi/PROJECT/version0318/getVide.py", line 223, in run
    infr = self.qInfr.get()
    File "/usr/lib/python3.7/multiprocessing/queues.py", line 93, in get
    with self._rlock:
    File "/usr/lib/python3.7/multiprocessing/synchronize.py", line 95, in enter
    return self._semlock.enter()
    KeyboardInterrupt
    Traceback (most recent call last):
    File "/home/pi/.local/lib/python3.7/site-packages/gevent/pywsgi.py", line 976, in handle_one_response
    self.run_application()
    File "/home/pi/.local/lib/python3.7/site-packages/geventwebsocket/handler.py", line 87, in run_application
    return super(WebSocketHandler, self).run_application()
    File "/home/pi/.local/lib/python3.7/site-packages/gevent/pywsgi.py", line 924, in run_application
    self.process_result()
    File "/home/pi/.local/lib/python3.7/site-packages/gevent/pywsgi.py", line 908, in process_result
    for data in self.result:
    File "/usr/lib/python3/dist-packages/werkzeug/debug/init.py", line 302, in debug_application
    for item in app_iter:
    File "/usr/lib/python3/dist-packages/werkzeug/wsgi.py", line 870, in next
    return self._next()
    File "/usr/lib/python3/dist-packages/werkzeug/wrappers.py", line 82, in _iter_encoded
    for item in iterable:
    File "main.py", line 166, in gen
    ret ,frame,gt = camera.get_frame()
    File "/home/pi/PROJECT/version0318/camera.py", line 36, in get_frame
    image =self.dispMain.dispFire.getframe()
    File "/home/pi/PROJECT/version0318/dispFire.py", line 62, in getframe
    fcomm = self.qComm.get()
    File "/usr/lib/python3.7/multiprocessing/queues.py", line 94, in get
    res = self._recv_bytes()
    File "/usr/lib/python3.7/multiprocessing/connection.py", line 216, in recv_bytes
    buf = self._recv_bytes(maxlength)
    File "/usr/lib/python3.7/multiprocessing/connection.py", line 407, in _recv_bytes
    buf = self._recv(4)
    File "/usr/lib/python3.7/multiprocessing/connection.py", line 379, in _recv
    chunk = read(handle, remaining)
    KeyboardInterrupt
    2020-03-23T02:15:33Z {'REMOTE_ADDR': '192.168.1.2', 'REMOTE_PORT': '52602', 'HTTP_HOST': '192.168.1.225:9000', (hidden keys: 23)} failed with KeyboardInterrupt

Process getInfr:
Traceback (most recent call last):
File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/home/pi/PROJECT/version0318/getInfr.py", line 147, in run
self.qInfr.get()
File "/usr/lib/python3.7/multiprocessing/queues.py", line 94, in get
res = self._recv_bytes()
File "/usr/lib/python3.7/multiprocessing/connection.py", line 216, in recv_bytes
buf = self._recv_bytes(maxlength)
File "/usr/lib/python3.7/multiprocessing/connection.py", line 407, in _recv_bytes
buf = self._recv(4)
File "/usr/lib/python3.7/multiprocessing/connection.py", line 379, in _recv
chunk = read(handle, remaining)
KeyboardInterrupt

2 I tried to test eventlet (uninstalling gevent). The log was caught as below.

Server initialized for eventlet.
main function

  • Restarting with stat
    Server initialized for eventlet.
    main function
  • Debugger is active!
  • Debugger PIN: 217-924-079
    (1932) wsgi starting up on http://0.0.0.0:9000
    (1932) accepted ('192.168.1.2', 52809)
    703c3352843d4454b746c56f33963434: Sending packet OPEN data {'sid': '703c3352843d4454b746c56f33963434', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}
    703c3352843d4454b746c56f33963434: Sending packet MESSAGE data 0
    192.168.1.2 - - [23/Mar/2020 10:20:45] "GET /socket.io/?EIO=3&transport=polling&t=N45CnBA HTTP/1.1" 200 349 0.001950
    703c3352843d4454b746c56f33963434: Received packet MESSAGE data 0/test,
    the web server receives 'connect' event(registered by server) 703c3352843d4454b746c56f33963434
    background_thread
    (1932) accepted ('192.168.1.2', 52810)
    (1932) accepted ('192.168.1.2', 52811)
    emitting event "my_response" to 703c3352843d4454b746c56f33963434 [/test]
    703c3352843d4454b746c56f33963434: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
    703c3352843d4454b746c56f33963434: Sending packet MESSAGE data 0/test
    192.168.1.2 - - [23/Mar/2020 10:20:45] "POST /socket.io/?EIO=3&transport=polling&t=N45CnCZ&sid=703c3352843d4454b746c56f33963434 HTTP/1.1" 200 223 0.005156
    703c3352843d4454b746c56f33963434: Received request to upgrade to websocket
    192.168.1.2 - - [23/Mar/2020 10:20:45] "GET /socket.io/?EIO=3&transport=polling&t=N45CnCa&sid=703c3352843d4454b746c56f33963434 HTTP/1.1" 200 183 0.000402
    192.168.1.2 - - [23/Mar/2020 10:20:45] "GET /socket.io/?EIO=3&transport=polling&t=N45CnCp&sid=703c3352843d4454b746c56f33963434 HTTP/1.1" 200 183 0.000447
    703c3352843d4454b746c56f33963434: Upgrade to websocket successful
    192.168.1.2 - - [23/Mar/2020 10:20:45] "GET / HTTP/1.1" 200 6050 0.040665
    the web server receives 'disconnect'event(registered by server) 703c3352843d4454b746c56f33963434
    emitting event "my_response" to 703c3352843d4454b746c56f33963434 [/test]
    703c3352843d4454b746c56f33963434: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO disconnected","count":0}]
    192.168.1.2 - - [23/Mar/2020 10:20:45] "GET /socket.io/?EIO=3&transport=websocket&sid=703c3352843d4454b746c56f33963434 HTTP/1.1" 200 0 0.146467
    192.168.1.2 - - [23/Mar/2020 10:20:47] "GET /img HTTP/1.1" 200 4767 0.009495
    camera ini
    mainFire class ini()
    mainfire glovar instance
    getvide finished
    wRecord ini
    display glovar instance
    ini glovar
    <globalvar.glovar object at 0xa9b711d0>
    gen1
    None
    generator function
    the network pid:1932; speed:0.004146; the fps:0.000000;time0:1584930056.173240;time3:1584930056.173240;difftime:1584930056.173240;framesum:6571346;\

When video stream works ,the flask-socketio doen't work,neither refresing nor switching page (broswer)
sometimes both of them does't work.
Thanks for your any suggetions or clues.
Best Regards Yan

@miguelgrinberg
Copy link
Owner

What made you decide it's not the hardware that is incompatible with gevent and eventlet? I don't understand your reasoning, if the server is hanging it is pretty much certain the code that manages your camera hardware is blocking, which means it is incompatible with gevent/eventlet.

@yanxiaoyan2020
Copy link
Author

yanxiaoyan2020 commented Mar 23, 2020

@miguelgrinberg
Maybe I didn't describe it clearly
When I got video stream from video files but not from cameras, gevent/eventlet doesn't work too.
So I think this issue not because of cameras. I am not sure whether multiprocessing of debian(raspberry) is incompatible with gevent/eventlet or not.
Best Regards Yan

@miguelgrinberg
Copy link
Owner

I am not sure whether multiprocessing of debian(raspberry) is incompatible with gevent/eventlet or not.

Yes, in general anything related to processes, threads or sockets is incompatible. Some things can work if you monkey patch the standard library. Have you done that?

@yanxiaoyan2020
Copy link
Author

@miguelgrinberg

  1. I install eventlet and monkey patch the standard library in win10
    import eventlet
    eventlet.monkey_patch()
    The log was caught as below

Server initialized for eventlet.

  • Restarting with stat
    Server initialized for eventlet.
  • Debugger is active!
  • Debugger PIN: 275-213-182
    (6160) wsgi starting up on http://0.0.0.0:9000
    (6160) accepted ('127.0.0.1', 51647)
    ba0ddf407c1d44838790d8e8202b191c: Sending packet OPEN data {'sid': 'ba0ddf407c1d44838790d8e8202b191c', 'upgrades': ['websocket'], 'pingTimeout': 60000,
    'pingInterval': 25000}
    ba0ddf407c1d44838790d8e8202b191c: Sending packet MESSAGE data 0
    127.0.0.1 - - [24/Mar/2020 09:40:48] "GET /socket.io/?EIO=3&transport=polling&t=N4ACmRN HTTP/1.1" 200 349 0.000000
    ba0ddf407c1d44838790d8e8202b191c: Received packet MESSAGE data 0/test,
    the web server receives 'connect' event(registered by server) ba0ddf407c1d44838790d8e8202b191c
    background_thread
    (6160) accepted ('127.0.0.1', 51650)
    emitting event "my_response" to ba0ddf407c1d44838790d8e8202b191c [/test]
    ba0ddf407c1d44838790d8e8202b191c: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
    ba0ddf407c1d44838790d8e8202b191c: Sending packet MESSAGE data 0/test
    127.0.0.1 - - [24/Mar/2020 09:40:48] "POST /socket.io/?EIO=3&transport=polling&t=N4ACmZ7&sid=ba0ddf407c1d44838790d8e8202b191c HTTP/1.1" 200 219 0.01559
    3
    ba0ddf407c1d44838790d8e8202b191c: Received request to upgrade to websocket
    127.0.0.1 - - [24/Mar/2020 09:40:48] "GET /socket.io/?EIO=3&transport=polling&t=N4ACmZ8&sid=ba0ddf407c1d44838790d8e8202b191c HTTP/1.1" 200 261 0.000000

ba0ddf407c1d44838790d8e8202b191c: Upgrade to websocket successful
ba0ddf407c1d44838790d8e8202b191c: Received packet PING data None
ba0ddf407c1d44838790d8e8202b191c: Sending packet PONG data None
ba0ddf407c1d44838790d8e8202b191c: Received packet MESSAGE data 2/test,["my_event",{"data":"I'm message!"}]
received event "my_event" from ba0ddf407c1d44838790d8e8202b191c [/test]
emitting event "my_response" to ba0ddf407c1d44838790d8e8202b191c [/test]
ba0ddf407c1d44838790d8e8202b191c: Sending packet MESSAGE data 2/test,["my_response",{"data":"I'm message!","count":1}]
ba0ddf407c1d44838790d8e8202b191c: Received packet MESSAGE data 2/test,["my_event",{"data":"I'm message!"}]
received event "my_event" from ba0ddf407c1d44838790d8e8202b191c [/test]
emitting event "my_response" to ba0ddf407c1d44838790d8e8202b191c [/test]
ba0ddf407c1d44838790d8e8202b191c: Sending packet MESSAGE data 2/test,["my_response",{"data":"I'm message!","count":2}]
(6160) accepted ('127.0.0.1', 51678)
127.0.0.1 - - [24/Mar/2020 09:41:33] "GET /img HTTP/1.1" 200 6660 0.017987
the web server receive 'disconnect' event(registered by server) ba0ddf407c1d44838790d8e8202b191c
emitting event "my_response" to ba0ddf407c1d44838790d8e8202b191c [/test]
ba0ddf407c1d44838790d8e8202b191c: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO disconnected","count":0}]
127.0.0.1 - - [24/Mar/2020 09:41:33] "GET /socket.io/?EIO=3&transport=websocket&sid=ba0ddf407c1d44838790d8e8202b191c HTTP/1.1" 200 0 44.589454
camera ini
mainFire class ini()
mainfire glovar instance
Server initialized for eventlet.
1d113842ce9b4fb28c0cc1e6106b1fd4: Sending packet OPEN data {'sid': '1d113842ce9b4fb28c0cc1e6106b1fd4', 'upgrades': ['websocket'], 'pingTimeout': 60000,
'pingInterval': 25000}
1d113842ce9b4fb28c0cc1e6106b1fd4: Sending packet MESSAGE data 0
127.0.0.1 - - [24/Mar/2020 09:41:38] "GET /socket.io/?EIO=3&transport=polling&t=N4ACxSp HTTP/1.1" 200 349 0.000000
getvide finished
Server initialized for eventlet.
(6160) accepted ('127.0.0.1', 51683)
(6160) accepted ('127.0.0.1', 51684)
1d113842ce9b4fb28c0cc1e6106b1fd4: Received packet MESSAGE data 0/test,
the web server receives 'connect' event(registered by server) 1d113842ce9b4fb28c0cc1e6106b1fd4
emitting event "my_response" to 1d113842ce9b4fb28c0cc1e6106b1fd4 [/test]
1d113842ce9b4fb28c0cc1e6106b1fd4: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
1d113842ce9b4fb28c0cc1e6106b1fd4: Sending packet MESSAGE data 0/test
127.0.0.1 - - [24/Mar/2020 09:41:41] "POST /socket.io/?EIO=3&transport=polling&t=N4ACyYf&sid=1d113842ce9b4fb28c0cc1e6106b1fd4 HTTP/1.1" 200 219 0.00200
0
127.0.0.1 - - [24/Mar/2020 09:41:42] "GET /socket.io/?EIO=3&transport=polling&t=N4ACyYg&sid=1d113842ce9b4fb28c0cc1e6106b1fd4 HTTP/1.1" 200 257 0.000997

1d113842ce9b4fb28c0cc1e6106b1fd4: Received request to upgrade to websocket
wRecord ini
display glovar instance
ini glovar
<globalvar.glovar object at 0x00000236CBF796D8>
127.0.0.1 - - [24/Mar/2020 09:41:42] "GET /socket.io/?EIO=3&transport=polling&t=N4ACzdx&sid=1d113842ce9b4fb28c0cc1e6106b1fd4 HTTP/1.1" 200 183 0.000996

1d113842ce9b4fb28c0cc1e6106b1fd4: Upgrade to websocket successful
Server initialized for eventlet. # I don't know what causes server eventlet init.
gen1
generator function
emitting event "my_response" to all [/test]
1d113842ce9b4fb28c0cc1e6106b1fd4: Sending packet MESSAGE data 2/test,["my_response",{"data":"prewarning","count":60}]
emitting event "my_response" to all [/test]
1d113842ce9b4fb28c0cc1e6106b1fd4: Sending packet MESSAGE data 2/test,["my_response",{"data":"warning","count":70}]

  1. I install eventlet and patched monkey in raspberrypi ,the log was caught .threading failed
  • Restarting with stat
  • Debugger is active!
  • Debugger PIN: 217-924-079
    (1918) wsgi starting up on http://0.0.0.0:9000
    (1918) accepted ('192.168.1.2', 52075)
    192.168.1.2 - - [24/Mar/2020 09:52:58] "GET /socket.io/?EIO=3&transport=polling&t=N4AG07E HTTP/1.1" 200 349 0.001341
    the web server receives 'connect' event(registered by server) 93eaa4d6960d454aa35d95448a72681e
    background_thread
    (1918) accepted ('192.168.1.2', 52076)
    192.168.1.2 - - [24/Mar/2020 09:52:58] "POST /socket.io/?EIO=3&transport=polling&t=N4AG0BI&sid=93eaa4d6960d454aa35d95448a72681e HTTP/1.1" 200 223 0.003140
    192.168.1.2 - - [24/Mar/2020 09:52:58] "GET /socket.io/?EIO=3&transport=polling&t=N4AG0BK&sid=93eaa4d6960d454aa35d95448a72681e HTTP/1.1" 200 183 0.000366
    (1918) accepted ('192.168.1.2', 52074)
    (1918) accepted ('192.168.1.2', 52082)
    (1918) accepted ('192.168.1.2', 52083)
    192.168.1.2 - - [24/Mar/2020 09:53:27] "GET /img HTTP/1.1" 200 6660 0.080426
    the web server receives 'disconnect'event(registered by server) 93eaa4d6960d454aa35d95448a72681e
    192.168.1.2 - - [24/Mar/2020 09:53:27] "GET /socket.io/?EIO=3&transport=websocket&sid=93eaa4d6960d454aa35d95448a72681e HTTP/1.1" 200 0 29.216549
    camera ini
    mainFire class ini()
    mainfire glovar instance
    Exception ignored in: <function _after_fork at 0xb653ff18>
    Traceback (most recent call last):
    File "/usr/lib/python3.7/threading.py", line 1343, in _after_fork
    assert len(_active) == 1
    AssertionError:
    192.168.1.2 - - [24/Mar/2020 09:53:27] "GET /socket.io/?EIO=3&transport=polling&t=N4AG7Kl HTTP/1.1" 200 349 0.002926
    the web server receives 'connect' event(registered by server) 2963f8e93ec5432c9cd19443300a338a
    192.168.1.2 - - [24/Mar/2020 09:53:27] "POST /socket.io/?EIO=3&transport=polling&t=N4AG7Ky&sid=2963f8e93ec5432c9cd19443300a338a HTTP/1.1" 200 223 0.005476
    (1918) accepted ('192.168.1.2', 52085)
    (1918) accepted ('192.168.1.2', 52086)
    192.168.1.2 - - [24/Mar/2020 09:53:27] "GET /socket.io/?EIO=3&transport=polling&t=N4AG7K-&sid=2963f8e93ec5432c9cd19443300a338a HTTP/1.1" 200 183 0.000914
    192.168.1.2 - - [24/Mar/2020 09:53:27] "GET /socket.io/?EIO=3&transport=polling&t=N4AG7LD&sid=2963f8e93ec5432c9cd19443300a338a HTTP/1.1" 200 183 0.000389
    getvide finished
    Exception ignored in: <function _after_fork at 0xb653ff18>
    Traceback (most recent call last):
    File "/usr/lib/python3.7/threading.py", line 1343, in _after_fork
    assert len(_active) == 1
    AssertionError:
    wRecord ini
    Exception ignored in: <function _after_fork at 0xb653ff18>
    Traceback (most recent call last):
    File "/usr/lib/python3.7/threading.py", line 1343, in _after_fork
    assert len(_active) == 1
    AssertionError:
    display glovar instance
    ini glovar
    <globalvar.glovar object at 0xaa3f3c50>
    gen1
    generator function
    ime3:1585014817.459856;difftime:1585014817.459856;framesum:7000502;the network pid:1918; speed:1702007.709081; the fps:25.020319;time0:158

several tests it,server/client can not work .
So I power off /on the raspberry pi .The log(infra images from file not from infram camera) was caught as below:
threading setup failed too

pi@raspberrypi:~/PROJECT/version0323 $ python3 main.py
Server initialized for eventlet.

  • Restarting with stat
    Server initialized for eventlet.
  • Debugger is active!
  • Debugger PIN: 217-924-079
    (979) wsgi starting up on http://0.0.0.0:9000
    (979) accepted ('192.168.1.2', 52422)
    (979) accepted ('192.168.1.2', 52423)
    192.168.1.2 - - [24/Mar/2020 10:02:41] "GET / HTTP/1.1" 200 6050 0.047029
    (979) accepted ('192.168.1.2', 52427)
    192.168.1.2 - - [24/Mar/2020 10:02:45] "GET /img HTTP/1.1" 200 6660 0.026753
    (979) accepted ('192.168.1.2', 52428)
    camera ini
    mainFire class ini()
    mainfire glovar instance
    Exception ignored in: <function _after_fork at 0xb651af18>
    Traceback (most recent call last):
    File "/usr/lib/python3.7/threading.py", line 1343, in _after_fork
    assert len(_active) == 1
    AssertionError:
    f4a36fbe02fb4636919a7f860006e8cf: Sending packet OPEN data {'sid': 'f4a36fbe02fb4636919a7f860006e8cf', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}
    f4a36fbe02fb4636919a7f860006e8cf: Sending packet MESSAGE data 0
    192.168.1.2 - - [24/Mar/2020 10:02:45] "GET /socket.io/?EIO=3&transport=polling&t=N4AIFSQ HTTP/1.1" 200 349 0.009350
    f4a36fbe02fb4636919a7f860006e8cf: Received packet MESSAGE data 0/test,
    the web server receives 'connect' event(registered by server) f4a36fbe02fb4636919a7f860006e8cf
    background_thread
    (979) accepted ('192.168.1.2', 52430)
    (979) accepted ('192.168.1.2', 52431)
    emitting event "my_response" to f4a36fbe02fb4636919a7f860006e8cf [/test]
    f4a36fbe02fb4636919a7f860006e8cf: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
    f4a36fbe02fb4636919a7f860006e8cf: Sending packet MESSAGE data 0/test
    192.168.1.2 - - [24/Mar/2020 10:02:45] "POST /socket.io/?EIO=3&transport=polling&t=N4AIFSk&sid=f4a36fbe02fb4636919a7f860006e8cf HTTP/1.1" 200 223 0.007150
    f4a36fbe02fb4636919a7f860006e8cf: Received request to upgrade to websocket
    192.168.1.2 - - [24/Mar/2020 10:02:45] "GET /socket.io/?EIO=3&transport=polling&t=N4AIFSm&sid=f4a36fbe02fb4636919a7f860006e8cf HTTP/1.1" 200 183 0.000429
    192.168.1.2 - - [24/Mar/2020 10:02:45] "GET /socket.io/?EIO=3&transport=polling&t=N4AIFSz&sid=f4a36fbe02fb4636919a7f860006e8cf HTTP/1.1" 200 183 0.000494
    f4a36fbe02fb4636919a7f860006e8cf: Upgrade to websocket successful
    getvide finished
    Exception ignored in: <function _after_fork at 0xb651af18>
    Traceback (most recent call last):
    File "/usr/lib/python3.7/threading.py", line 1343, in _after_fork
    assert len(_active) == 1
    AssertionError:
    wRecord ini
    Exception ignored in: <function _after_fork at 0xb651af18>
    Traceback (most recent call last):
    File "/usr/lib/python3.7/threading.py", line 1343, in _after_fork
    assert len(_active) == 1
    AssertionError:
    display glovar instance
    ini glovar
    <globalvar.glovar object at 0xaa3b7ad0>
    gen1
    generator function
    the network pid:979; speed:0.004496; the fps:0.000000;time0:1585015375.073520;time3:1585015375.073520;difftime:1585015375.073520;framesum:7126814;
    the network pid:979; speed:1845913.741718; the fps:25.301311;time0:1585015379.065408;time3:1585015379.065408;difftime:3.991888;framesum:7368681;
    the network pid:979; speed:1822590.388785; the fps:25.011261;time0:1585015383.103589;time3:1585015383.103589;difftime:4.038181;framesum:7359950;
    the network pid:979; speed:1820564.973465; the fps:25.024076;time0:1585015387.139702;time3:1585015387.139702;difftime:4.036113;framesum:7348006;
    f4a36fbe02fb4636919a7f860006e8cf: Received packet PING data None
    f4a36fbe02fb4636919a7f860006e8cf: Sending packet PONG data None
    the network pid:979; speed:1753594.313527; the fps:24.991061;time0:1585015391.181147;time3:1585015391.181147;difftime:4.041445;framesum:7087055;
    f4a36fbe02fb4636919a7f860006e8cf: Received packet MESSAGE data 2/test,["my_event",{"data":"I'm message!"}]
    received event "my_event" from f4a36fbe02fb4636919a7f860006e8cf [/test]
    emitting event "my_response" to f4a36fbe02fb4636919a7f860006e8cf [/test]
    f4a36fbe02fb4636919a7f860006e8cf: Sending packet MESSAGE data 2/test,["my_response",{"data":"I'm message!","count":1}]
    the network pid:979; speed:1772149.283583; the fps:25.023078;time0:1585015395.217421;time3:1585015395.217421;difftime:4.036274;framesum:7152880;
    f4a36fbe02fb4636919a7f860006e8cf: Received packet MESSAGE data 2/test,["my_event",{"data":"I'm message!"}]
    received event "my_event" from f4a36fbe02fb4636919a7f860006e8cf [/test]
    emitting event "my_response" to f4a36fbe02fb4636919a7f860006e8cf [/test]
    f4a36fbe02fb4636919a7f860006e8cf: Client is gone, closing socket
    the web server receives 'disconnect'event(registered by server) f4a36fbe02fb4636919a7f860006e8cf
    emitting event "my_response" to f4a36fbe02fb4636919a7f860006e8cf [/test]
    f4a36fbe02fb4636919a7f860006e8cf: Client is gone, closing socket
    f4a36fbe02fb4636919a7f860006e8cf: Client is gone, closing socket
    ^CException in thread QueueFeederThread:
    Traceback (most recent call last):
    File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
    File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
    File "/usr/lib/python3.7/multiprocessing/queues.py", line 236, in _feed
    obj = _ForkingPickler.dumps(obj)
    File "/usr/lib/python3.7/multiprocessing/reduction.py", line 51, in dumps
    cls(buf, protocol).dump(obj)
    File "/usr/lib/python3.7/multiprocessing/reduction.py", line 41, in init
    self.dispatch_table.update(self._extra_reducers)
    KeyboardInterrupt

Process dectFire:
Traceback (most recent call last):
File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/home/pi/PROJECT/version0323/dectFire.py", line 71, in run
contours = self.fireDect.FireCheck(frame)
File "/home/pi/PROJECT/version0323/FireDetect.py", line 199, in FireCheck
contours_ret= self.findContoursFromVideoAndInfrared(frame,infrared)
File "/home/pi/PROJECT/version0323/FireDetect.py", line 153, in findContoursFromVideoAndInfrared
binary_video = self.findFirePixFromVideo(frame)
File "/home/pi/PROJECT/version0323/FireDetect.py", line 137, in findFirePixFromVideo
S = 1.0 - 3.0 * (minValue / Dot)
KeyboardInterrupt

pi@raspberrypi:~/PROJECT/version0323 $ python3 main.py
Server initialized for eventlet.

  • Restarting with stat
    Server initialized for eventlet.
  • Debugger is active!
  • Debugger PIN: 217-924-079
    (990) wsgi starting up on http://0.0.0.0:9000
    (990) accepted ('192.168.1.2', 52770)
    192.168.1.2 - - [24/Mar/2020 10:11:53] "GET / HTTP/1.1" 200 6050 0.073835
    192.168.1.2 - - [24/Mar/2020 10:11:56] "GET /img HTTP/1.1" 200 6660 0.011928
    (990) accepted ('192.168.1.2', 52772)
    camera ini
    mainFire class ini()
    mainfire glovar instance
    Exception ignored in: <function _after_fork at 0xb6494f18>
    Traceback (most recent call last):
    File "/usr/lib/python3.7/threading.py", line 1343, in _after_fork
    assert len(_active) == 1
    AssertionError:
    1f2f7533464c49f7b11ad3e244be99ac: Sending packet OPEN data {'sid': '1f2f7533464c49f7b11ad3e244be99ac', 'upgrades': ['websocket'], 'pingTimeout': 60000, 'pingInterval': 25000}
    1f2f7533464c49f7b11ad3e244be99ac: Sending packet MESSAGE data 0
    192.168.1.2 - - [24/Mar/2020 10:11:56] "GET /socket.io/?EIO=3&transport=polling&t=N4AKL_K HTTP/1.1" 200 349 0.006890
    1f2f7533464c49f7b11ad3e244be99ac: Received packet MESSAGE data 0/test,
    the web server receives 'connect' event(registered by server) 1f2f7533464c49f7b11ad3e244be99ac
    background_thread
    (990) accepted ('192.168.1.2', 52773)
    emitting event "my_response" to 1f2f7533464c49f7b11ad3e244be99ac [/test]
    1f2f7533464c49f7b11ad3e244be99ac: Sending packet MESSAGE data 2/test,["my_response",{"data":"socketIO connected","count":0}]
    1f2f7533464c49f7b11ad3e244be99ac: Sending packet MESSAGE data 0/test
    192.168.1.2 - - [24/Mar/2020 10:11:56] "POST /socket.io/?EIO=3&transport=polling&t=N4AKL_X&sid=1f2f7533464c49f7b11ad3e244be99ac HTTP/1.1" 200 223 0.006478
    1f2f7533464c49f7b11ad3e244be99ac: Received request to upgrade to websocket
    192.168.1.2 - - [24/Mar/2020 10:11:56] "GET /socket.io/?EIO=3&transport=polling&t=N4AKL_X.0&sid=1f2f7533464c49f7b11ad3e244be99ac HTTP/1.1" 200 183 0.000410
    192.168.1.2 - - [24/Mar/2020 10:11:56] "GET /socket.io/?EIO=3&transport=polling&t=N4AKL_l&sid=1f2f7533464c49f7b11ad3e244be99ac HTTP/1.1" 200 183 0.000475
    1f2f7533464c49f7b11ad3e244be99ac: Upgrade to websocket successful

Best Regards Yan

@miguelgrinberg
Copy link
Owner

The eventlet initialization that gets repeated is probably caused by you or one of your dependencies using the fork() call to fork your server process.

The assert error is an open issue with eventlet, see eventlet/eventlet#592.

@yanxiaoyan2020
Copy link
Author

@miguelgrinberg
1 the eventlet initialization that gets repeated is probaly caused by my refreshing browser(socketio client).
2 I adding workaround according to eventlet/eventlet#592 as below
The assert error can reproduce again. Maybe adding code is not correct.
I test workaround in python shell,it works.

import eventlet
eventlet.monkey_patch()
import threading
import __original_module_threading
__original_module_threading.current_thread.globals['_active']=threading._active

File "/usr/lib/python3.7/threading.py", line 1343, in _after_fork
Exception ignored in: <function _after_fork at 0xb64ccf18>
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 1343, in _after_fork
assert len(_active) == 1
AssertionError:

3 When I tested as eventlet with patch,four process is running,but infra image can get some frames ,then failed to get.
sometimes socketio failed no refreshing browser,then can not work again. the log was caught as below.
299e38bd41794ac8ac7cd0d7479bfe81: Client is gone, closing socket
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/eventlet/wsgi.py", line 566, in handle_one_response
result = self.application(self.environ, start_response)
File "/usr/lib/python3/dist-packages/flask/app.py", line 2309, in call
return self.wsgi_app(environ, start_response)
File "/home/pi/.local/lib/python3.7/site-packages/flask_socketio/init.py", line 46, in call
start_response)
File "/home/pi/.local/lib/python3.7/site-packages/engineio/middleware.py", line 60, in call
return self.engineio_app.handle_request(environ, start_response)
File "/home/pi/.local/lib/python3.7/site-packages/socketio/server.py", line 555, in handle_request
return self.eio.handle_request(environ, start_response)
File "/home/pi/.local/lib/python3.7/site-packages/engineio/server.py", line 377, in handle_request
environ, start_response)
File "/home/pi/.local/lib/python3.7/site-packages/engineio/socket.py", line 108, in handle_get_request
start_response)
File "/home/pi/.local/lib/python3.7/site-packages/engineio/socket.py", line 152, in _upgrade_websocket
return ws(environ, start_response)
File "/home/pi/.local/lib/python3.7/site-packages/engineio/async_drivers/eventlet.py", line 20, in call
return super(WebSocketWSGI, self).call(environ, start_response)
File "/home/pi/.local/lib/python3.7/site-packages/eventlet/websocket.py", line 130, in call
self.handler(ws)
File "/home/pi/.local/lib/python3.7/site-packages/engineio/socket.py", line 178, in _websocket_handler
pkt = ws.wait()
File "/home/pi/.local/lib/python3.7/site-packages/eventlet/websocket.py", line 788, in wait
for i in self.iterator:
File "/home/pi/.local/lib/python3.7/site-packages/eventlet/websocket.py", line 643, in _iter_frames
message = self._recv_frame(message=fragmented_message)
File "/home/pi/.local/lib/python3.7/site-packages/eventlet/websocket.py", line 669, in _recv_frame
header = recv(2)
File "/home/pi/.local/lib/python3.7/site-packages/eventlet/websocket.py", line 578, in _get_bytes
d = self.socket.recv(numbytes - len(data))
File "/home/pi/.local/lib/python3.7/site-packages/eventlet/greenio/base.py", line 366, in recv
return self._recv_loop(self.fd.recv, b'', bufsize, flags)
File "/home/pi/.local/lib/python3.7/site-packages/eventlet/greenio/base.py", line 360, in _recv_loop
self._read_trampoline()
File "/home/pi/.local/lib/python3.7/site-packages/eventlet/greenio/base.py", line 331, in _read_trampoline
timeout_exc=socket_timeout('timed out'))
File "/home/pi/.local/lib/python3.7/site-packages/eventlet/greenio/base.py", line 210, in _trampoline
mark_as_closed=self._mark_as_closed)
File "/home/pi/.local/lib/python3.7/site-packages/eventlet/hubs/init.py", line 159, in trampoline
return hub.switch()
File "/home/pi/.local/lib/python3.7/site-packages/eventlet/hubs/hub.py", line 298, in switch
return self.greenlet.switch()
socket.timeout: timed out

192.168.1.2 - - [25/Mar/2020 1
Best Regards Yan

@yanxiaoyan2020
Copy link
Author

yanxiaoyan2020 commented Mar 25, 2020

@miguelgrinberg
Current envirement use long-polling, exept that disconnects are detected after about a minute. Server emiting information to client(browser,socketio) and client emiting information to server can work well,informaiton without delay.
I am not sure whether long-polling has other issue or not.
Best Regards Yan

@miguelgrinberg
Copy link
Owner

The only issue with long-polling is that it is less efficient than WebSocket. If the performance is fine for your needs, then I don't see a reason to worry.

@yanxiaoyan2020
Copy link
Author

@miguelgrinberg
It's nice of you to response this question . I always appreciated your help.
Would you please have any suggestions or clues of python package for django real time communication between Browser/Server? How about dwebsocket?

Best Regard Yan

@miguelgrinberg
Copy link
Owner

You can use python-socketio, the package on which Flask-SocketIO is based.

@yanxiaoyan2020
Copy link
Author

@miguelgrinberg
I will learn python-socketio,and engine.io framework and try to use in django s/b real time communication.
Best Regards Yan

@yanxiaoyan2020
Copy link
Author

yanxiaoyan2020 commented Apr 2, 2020

@miguelgrinberg
I found that 'main' enters twice when I added flask-socketio. the log as below:
I hope to call 'main' once. Because some global variable will be reset when 'main' be called again.
How can I resolve this question?
main enter #my print when if name == 'main': is called

  • Serving Flask app "main" (lazy loading)
  • Environment: production
    WARNING: Do not use the development server in a production environment.
    Use a production WSGI server instead.
  • Debug mode: on
    main enter #my print too when if name == 'main': is called
    the web server receives 'connect' event(registered by server) 8c59009447314091b5e0cd7f2208a7f8
    background_thread

appreciate for any suggestions and clues.
Best Regards Yan

@miguelgrinberg
Copy link
Owner

You are running Flask in debug mode. This has nothing to do with Socket.IO Flask runs a master process and a child process. This is how the reloader works.

@yanxiaoyan2020
Copy link
Author

@miguelgrinberg
1 Thanks for your response. The reloader is caused by runing Flaks in debug mode.
2 I have already closed the socketio logging as below
call SocketIO(app,async_mode=async_mode,logger=False,engineio_logger=False)
There are still polling logs printing as below:
How can I close below polling logs?
192.168.1.2 - - [03/Apr/2020 17:19:55] "GET /socket.io/?EIO=3&transport=polling&t=N4_MDNq&sid=5345d05e8c3f463187d07670198fd9fd HTTP/1.1" 200 -
192.168.1.2 - - [03/Apr/2020 17:19:55] "GET /static/favicon.ico HTTP/1.1" 404 -
192.168.1.2 - - [03/Apr/2020 17:19:56] "GET /socket.io/?EIO=3&transport=polling&t=N4_MDdQ&sid=5345d05e8c3f463187d07670198fd9fd HTTP/1.1" 200 -
192.168.1.2 - - [03/Apr/2020 17:19:57] "GET /socket.io/?EIO=3&transport=polling&t=N4_MDt5&sid=5345d05e8c3f463187d07670198fd9fd HTTP/1.1" 200 -
192.168.1.2 - - [03/Apr/2020 17:19:58] "GET /socket.io/?EIO=3&transport=polling&t=N4_ME6m&sid=5345d05e8c3f463187d07670198fd9fd HTTP/1.1" 200 -
-bash: 192.168.1.2:未找到命令
192.168.1.2 - - [03/Apr/2020 17:19:59] "GET /socket.io/?EIO=3&transport=polling&t=N4_MEMR&sid=5345d05e8c3f463187d07670198fd9fd HTTP/1.1" 200 -
192.168.1.2 - - [03/Apr/2020 17:20:00] "GET /socket.io/?EIO=3&transport=polling&t=N4_MEc3&sid=5345d05e8c3f463187d07670198fd9fd HTTP/1.1" 200 -
192.168.1.2 - - [03/Apr/2020 17:20:01] "GET /socket.io/?EIO=3&transport=polling&t=N4_MErl&sid=5345d05e8c3f463187d07670198fd9fd HTTP/1.1" 200 -
pi@raspberrypi:~/PROJECT/version0331 $ 192.168.1.2 - - [03/Apr/2020 17:19:51] "GET /socket.io/?EIO=3&transport=polling&t=N4_MCPB&sid=5345d05e8c3f463187d07670198fd9fd HTTP/1.1" 200 -
192.168.1.2 - - [03/Apr/2020 17:20:05] "GET /socket.io/?EIO=3&transport=polling&t=N4_MFqQ&sid=5345d05e8c3f463187d07670198fd9fd HTTP/1.1" 200 -
192.168.1.2 - - [03/Apr/2020 17:20:06] "GET /socket.io/?EIO=3&transport=polling&t=N4_MG44&sid=5345d05e8c3f463187d07670198fd9fd HTTP/1.1" 200 -
192.168.1.2 - - [03/Apr/2020 17:20:07] "GET /socket.io/?EIO=3&transport=polling&t=N4_MGJi&sid=5345d05e8c3f463187d07670198fd9fd
Appreciate for any suggestions and clues.
Best Regards Yan

@miguelgrinberg
Copy link
Owner

@yanxiaoyan2020 those are logs printed by the web server that you are using. If you are using the Flask development server, see this: https://stackoverflow.com/questions/14888799/disable-console-messages-in-flask-server.

@yanxiaoyan2020
Copy link
Author

@miguelgrinberg
About django web server real time communication between server and client. the Client/browser using Flask-SocketIO client written by jquery and the service using python-socketio server. Is this design feasible?
Appreciate for any suggestions and clues.
Best Regard Yan

@miguelgrinberg
Copy link
Owner

There is no Flask-SocketIO client for JavaScript/jQuery, you'll have to look elsewhere for that, for example the official socket.io-client project. There is a Django example in the python-socketio repository, by the way.

@yanxiaoyan2020
Copy link
Author

@miguelgrinberg
Thanks for your response. Maybe I didn't describe it clearly.
1 There is Flask-SocketIO client example for jquery (https://github.com/miguelgrinberg/Flask-SocketIO/blob/master/example/templates/index.html)
2 Is there socket.io-client in python-socketio repository. If so,how can I use it in Django web views files . I used to think that python-socketio is C/S (client/server) model but not B/S(brower/server) model . Maybe my understanding is wrong.
Appreciate for any suggestions or clues
Best Regards Yan

@miguelgrinberg
Copy link
Owner

As I said above, there is an example that uses Django in the python-socketio repository. I'm not sure what you mean by browser/server. This package is client/server. The browser is the client.

@yanxiaoyan2020
Copy link
Author

@miguelgrinberg
I found the example that uses Django in the python-socketio repository. I got it.
Thanks for your response. Appreciate for you helps
Best Regards Yan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants