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

'Björn Pedersen' via cherrypy-users <cherrypy-users-/[email protected]> Wed, 28 Feb 2018 00:01:18 -0800 (PST)
Newsgroups gmane.comp.python.cherrypy
Message-ID <[email protected]>
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 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 cherrypy-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
To post to this group, send email to cherrypy-users-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
Visit this group at https://groups.google.com/group/cherrypy-users.
For more options, visit https://groups.google.com/d/optout.