Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

added close() to servers #38

Merged
merged 1 commit into from
Sep 16, 2014
Merged

added close() to servers #38

merged 1 commit into from
Sep 16, 2014

Conversation

ritksm
Copy link
Contributor

@ritksm ritksm commented Sep 10, 2014

so we can manually close/stop server

@wooparadog
Copy link
Member

or you could try using gunicorn_thrift to run your thrift server. And closing server should be as simple as sending the master process a SIGTERM

@ritksm
Copy link
Contributor Author

ritksm commented Sep 10, 2014

@wooparadog I tested my code with gunicorn_thrift, it works fine.

However, I think that thriftpy server should come with a way to stop server after cleanup, instead of introducing some gunicorn features that I don't need.

@lxyu
Copy link
Contributor

lxyu commented Sep 16, 2014

when could the close() method be called as the serve() already blocked the main process?

@ritksm
Copy link
Contributor Author

ritksm commented Sep 16, 2014

@lxyu
My case is, when thrift server is going to shutdown, I have to do some cleanup, close some sockets blahblah. So I use signal to handle system signal like SIGQUIT, so there will be a signal handler function where I do clean up.
However, due to server.serve() only respond to KeyboardInterrupt, so I have to raise a KeyboardInterrupt in order to shutdown the thrift server, that seems extremely inappropriate and weird, so a better solution would be providing a close() function to shutdown the server.

lxyu added a commit that referenced this pull request Sep 16, 2014
added close() to servers
@lxyu lxyu merged commit bc6e8ef into Thriftpy:develop Sep 16, 2014
@miphip
Copy link

miphip commented Apr 25, 2015

The current implementation (0.3.0) doesn't work.

TSimpleServer will only look at self.closed when processor.process returns, i.e. after processing some packets. Then it will get caught in trans.accept() waiting for new client session.

TThreadedServer will only look at self.closed once a client session ends. It can't be stopped if it doesn't gave or get any client sessions since it is stuck in trans.accept() waiting for a client session.

To support stopping the server, a socket timeout must be set causing "socket.accept" and "processor.process" to return regularly to check is self.closed has been set.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants