server won't exit when a streaming connection is active

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

server won't exit when a streaming connection is active

Dereck
Hi all, I am pretty new to cherrypy and have been playing around with it and ran into an issue. I have my server serving up a streaming response for mjpeg. It work wonderfully until I want to stop the server. It will not exit if there is an active connection. The output gets stuck at "Stopping Engine Bus". Is there a way to force the server to shutdown even if there are active connections. My code is as follows:


class HelloWorld(object):
    @cherrypy.expose
    def index(self):
        cherrypy.response.headers['Content-Type']='multipart/x-mixed-replace; boundary=frame'
        def content():
            while True:
                yield (b'--frame\r\n'
                       b'Content-Type: image/jpeg\r\n\r\n'+ frame + b'\r\n')
        return content()
    index._cp_config = {'response.stream': True}


def Start():
    cherrypy.config.update({'server.socket_host': '0.0.0.0', 'server.socket_port': 9090})
    cherrypy.tree.mount(HelloWorld(),"/")
    cherrypy.engine.start()


def Stop():
    cherrypy.engine.stop()
    cherrypy.engine.exit()




--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: server won't exit when a streaming connection is active

morecowbell
add an asyc signal handler. something lie this should work:

def sig_handler(signum, frame):
    Stop()  # your Stop() function

# register the handlers before you call your  Start(), eg.:

signal.signal(signal.SIGUSR1, sign_handler)
signal.signal(signal.SIGUSR2, sign_handler)

check out https://pymotw.com/3/signal/index.html


On Sunday, February 18, 2018 at 9:42:31 AM UTC-8, Dereck wrote:
Hi all, I am pretty new to cherrypy and have been playing around with it and ran into an issue. I have my server serving up a streaming response for mjpeg. It work wonderfully until I want to stop the server. It will not exit if there is an active connection. The output gets stuck at "Stopping Engine Bus". Is there a way to force the server to shutdown even if there are active connections. My code is as follows:


class HelloWorld(object):
    @cherrypy.expose
    def index(self):
        cherrypy.response.headers['Content-Type']='multipart/x-mixed-replace; boundary=frame'
        def content():
            while True:
                yield (b'--frame\r\n'
                       b'Content-Type: image/jpeg\r\n\r\n'+ frame + b'\r\n')
        return content()
    index._cp_config = {'response.stream': True}


def Start():
    cherrypy.config.update({'server.socket_host': '0.0.0.0', 'server.socket_port': 9090})
    cherrypy.tree.mount(HelloWorld(),"/")
    cherrypy.engine.start()


def Stop():
    cherrypy.engine.stop()
    cherrypy.engine.exit()




--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: server won't exit when a streaming connection is active

Dereck
That looks like it does get the Stop method to be called but it still hangs on the "Engine bus stopping" and won't continue unless you close any active connections in the browser. Is there a way to override this so that it doesn't have to wait for there to be no active connections?

On Monday, February 19, 2018 at 4:59:10 AM UTC-7, morecowbell wrote:
add an asyc signal handler. something lie this should work:

def sig_handler(signum, frame):
    Stop()  # your Stop() function

# register the handlers before you call your  Start(), eg.:

signal.signal(signal.SIGUSR1, sign_handler)
signal.signal(signal.SIGUSR2, sign_handler)

check out <a href="https://pymotw.com/3/signal/index.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fpymotw.com%2F3%2Fsignal%2Findex.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF8R6QlPd7TytxJxkqbWrYkJ2tkBw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fpymotw.com%2F3%2Fsignal%2Findex.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF8R6QlPd7TytxJxkqbWrYkJ2tkBw&#39;;return true;">https://pymotw.com/3/signal/index.html


On Sunday, February 18, 2018 at 9:42:31 AM UTC-8, Dereck wrote:
Hi all, I am pretty new to cherrypy and have been playing around with it and ran into an issue. I have my server serving up a streaming response for mjpeg. It work wonderfully until I want to stop the server. It will not exit if there is an active connection. The output gets stuck at "Stopping Engine Bus". Is there a way to force the server to shutdown even if there are active connections. My code is as follows:


class HelloWorld(object):
    @cherrypy.expose
    def index(self):
        cherrypy.response.headers['Content-Type']='multipart/x-mixed-replace; boundary=frame'
        def content():
            while True:
                yield (b'--frame\r\n'
                       b'Content-Type: image/jpeg\r\n\r\n'+ frame + b'\r\n')
        return content()
    index._cp_config = {'response.stream': True}


def Start():
    cherrypy.config.update({'server.socket_host': '0.0.0.0', 'server.socket_port': 9090})
    cherrypy.tree.mount(HelloWorld(),"/")
    cherrypy.engine.start()


def Stop():
    cherrypy.engine.stop()
    cherrypy.engine.exit()




--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: server won't exit when a streaming connection is active

Björn Pedersen
Hi,

you probably need to put some stop-handling into your loop:

 while not stop_request:
    <loop code>

or
while True:
    if stop_request:
        raise <some appropriate error>
   <loop code>


the the Stop() method should set stop_request to True.

Depending on the full  design, stop_request  can of course also be a class member.


Björn

Am Mittwoch, 2
1. Februar 2018 19:52:48 UTC+1 schrieb Dereck:
That looks like it does get the Stop method to be called but it still hangs on the "Engine bus stopping" and won't continue unless you close any active connections in the browser. Is there a way to override this so that it doesn't have to wait for there to be no active connections?

On Monday, February 19, 2018 at 4:59:10 AM UTC-7, morecowbell wrote:
add an asyc signal handler. something lie this should work:

def sig_handler(signum, frame):
    Stop()  # your Stop() function

# register the handlers before you call your  Start(), eg.:

signal.signal(signal.SIGUSR1, sign_handler)
signal.signal(signal.SIGUSR2, sign_handler)

check out <a href="https://pymotw.com/3/signal/index.html" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fpymotw.com%2F3%2Fsignal%2Findex.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF8R6QlPd7TytxJxkqbWrYkJ2tkBw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fpymotw.com%2F3%2Fsignal%2Findex.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF8R6QlPd7TytxJxkqbWrYkJ2tkBw&#39;;return true;">https://pymotw.com/3/signal/index.html


On Sunday, February 18, 2018 at 9:42:31 AM UTC-8, Dereck wrote:
Hi all, I am pretty new to cherrypy and have been playing around with it and ran into an issue. I have my server serving up a streaming response for mjpeg. It work wonderfully until I want to stop the server. It will not exit if there is an active connection. The output gets stuck at "Stopping Engine Bus". Is there a way to force the server to shutdown even if there are active connections. My code is as follows:


class HelloWorld(object):
    @cherrypy.expose
    def index(self):
        cherrypy.response.headers['Content-Type']='multipart/x-mixed-replace; boundary=frame'
        def content():
            while True:
                yield (b'--frame\r\n'
                       b'Content-Type: image/jpeg\r\n\r\n'+ frame + b'\r\n')
        return content()
    index._cp_config = {'response.stream': True}


def Start():
    cherrypy.config.update({'server.socket_host': '0.0.0.0', 'server.socket_port': 9090})
    cherrypy.tree.mount(HelloWorld(),"/")
    cherrypy.engine.start()


def Stop():
    cherrypy.engine.stop()
    cherrypy.engine.exit()




--
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.