Re: Client exit handling. Is there an example?
Irmen de Jong <[email protected]>
| Newsgroups | gmane.comp.python.pyro |
|---|---|
| Message-ID | <[email protected]> |
On 15-6-2013 10:00, Vernon D. Cole wrote: > I am working on a project to build a remote proxy database access server. [The goal is > to permit a django client running on Linux to manipulate a Microsoft SQL Server > database.] Pyro4 is used to carry queries from the Linux client to a Windows host. It is > working well enough that I am starting to get ready to put it into limited production. > There are a hundred little things (*) that it does not do perfectly yet, but all of the > basics are working. > > One major problem remaining is that the server is too reliable. If a client program goes > away unexpectedly (this is Nigeria, the Internet, and the electricity, are not always > reliable) the proxy still keeps the database connection open, hanging there in mid > transaction forever. My only way of clearing this at present is to hit <control-Break> > on the proxy server. This may be fine for testing, but cannot be the answer in full > production. I need some method or methods to trigger cleanup when a client ceases to > communicate. A Python exit trigger on the client would help, but ultimately something > like a heartbeat timer may be the only answer. > > Does anyone have such a partner-failure detector that you would be willing to share? Perhaps you can do something with the COMMTIMEOUT config item on the server side? It will make the connections timeout after the given time if no more data is received. That connection will then be terminated. The problem with this is, that a client that is still connected but simply takes too long between remote method calls, will encounter a ConnectionClosedError. But you can use Pyro's auto-reconnect feature to deal with this. For instance, you can create a special Proxy class that you use instead of Pyro's default, which will automatically do this for you on every method call. Or you can do it explicitly in your own code like the 'autoreconnect' client example does. A possible implementation is here: https://gist.github.com/irmen/5787860 Notice that the server object requires a special 'ping' method to exist for this to work. I might look into a nicer way to do this in the near future. Cheers Irmen ------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev