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

Dereck <[email protected]> Wed, 21 Feb 2018 10:52:48 -0800 (PST)
Newsgroups gmane.comp.python.cherrypy
Message-ID <[email protected]>
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.