[Soap-Python] Running a SOAPpy server in a thread

Marcus Priesch marcus at priesch.priv.at
Wed Jan 5 20:41:06 CET 2011


Am Mittwoch, den 05.01.2011, 13:01 -0500 schrieb Kevin Anthony:
> I need to be able to start and stop the soap server programmatically.
> 
> There doesn't seem to be a way to stop serve_forever without killing
> the entire program.

yes, there is no way to kill a thread :( 

... but maybe you would like to join in on the multiprocessing module :)
its usage is nearly identical - as you can always kill a process ... :)

have fun,
m.

> 
> On Wed, Jan 5, 2011 at 2:18 AM, Marcus Priesch <marcus at priesch.priv.at> wrote:
> >
> > Hi Kevin,
> >
> > why do you want to exit the thread on demand ?
> >
> > wouldnt
> >
> >  t = threading.Thread (target = self._server.server_forever)
> >  t.daemon = True
> >  t.start ()
> >
> > be sufficient (i dont know exactly if there is a server_forever method
> > but it would simply be a while True: handle_request() loop) ?
> >
> > however, as far as i understand your code you are witing after each
> > handled request ?!?
> >
> > regards,
> > m.
> >
> > Am Montag, den 03.01.2011, 17:02 -0500 schrieb Kevin Anthony:
> > > I'm writing a SOAPpy server in a thread, and having a problem handling
> > > the exiting
> > >
> > >
> > > What happens is handle_request() blocks until a request comes in. so
> > > the thread exit's normally once a request comes in, but the server
> > > could sit running for hours before a request comes in.
> > > is there a non-blocking method i can call before i call handle_request
> > >
> > >
> > > I've played around with socket timeouts but haven't had much success.
> > >  is there a way to do this?
> > >
> > >
> > > here's my code current code:
> > >
> > >
> > >         def run(self):
> > >                 self._server = SOAPpy.SOAPServer(self._addr)
> > >                 self._server.registerObject(self,self._NS)
> > >                 logging.info("Starting Soap Server (ctrl+c to stop)")
> > >                 while not self._stopevent.isSet():
> > >                         self._server.handle_request()
> > >                         self._stopevent.wait(self._sleepPeriod)
> > >
> > >
> > >         def join(self, timeout=None):
> > >                 self._stopevent.set()
> > >                 threading.Thread.join(self, timeout)
> > >                 self._server.server_close()
> > >                 logging.warning("Exiting Thread :%s"
> > > %(self.getName()))
> > >
> > >
> > >
> > > --
> > > Thanks
> > > Kevin Anthony
> > > www.NoSideRacing.com
> > > 732.793.3473
> > >
> > >
> > > _______________________________________________
> > > Soap mailing list
> > > Soap at python.org
> > > http://mail.python.org/mailman/listinfo/soap
> >
> >
> > _______________________________________________
> > Soap mailing list
> > Soap at python.org
> > http://mail.python.org/mailman/listinfo/soap
> 
> 
> 
> --
> Thanks
> Kevin Anthony
> www.NoSideRacing.com
> 732.793.3473




More information about the Soap mailing list