well, you could always do (assuming you have 2 threads)
on the serving thread, you start with this function:
def startServer()
try:
#init code yada yada
#start it up!
server.serve()
except (SystemExit, KeyboardInterrupt):
#any shutdown code, closing sockets goes here
return
and on the other thread:
raise SystemExit
or even serverthread.terminate()
On Tue, Aug 30, 2011 at 9:51 PM, Francisco Byun <[email protected]> wrote:
> Same question here.
>
> I'm trying to write a test code for our project, which temporarily creates a
> TServer object and serve() it on a thread, and perform test codes, and then
> terminate it. But I just can't figure out howto. I think if TServer
> implementation had stop() method, I can try: (psuedo code)
>
> *import thread*
> *server_instance, handler_instance = get_thrift_server()*
> *
> *
> *thread.start_new_thread(server_instance.serve, tuple())*
> *
> *
> *run_tests()*
> *
> *
> *server_instance.stop()*
>
> I tried "sys.exit(0)" and many other ways, but all failed to terminate the
> thread which runs TServer.serve() ... Any suggestions?
>
> --
> Francisco Byun
>
> 2011/8/11 Kyle <[email protected]>
>
>> There doesn't seem to be a 'stop' method in any of the python TServer
>> implementations. I know the method exists in the Java API.
>> I'd like to have a second thread watching activity, and when the
>> server seems inactive, hit the stop button and shutdown the program.
>> But all of the server loops are 'while True' and waiting for an
>> exception.
>>
>> Any ideas?
>>
>> Kyle
>>
>
--
Dvir Volk
System Architect, DoAT, http://doat.com