How to build Twisted servers capable of exchanging hot code in Python?

I developed a set of audio streaming server, they all use Twisted, and they, of course, are in Python. They work, but the problem bothers me when I find some errors on a running server or want to add something to the server, I need to stop them and start. Unlike HTTP servers, it is still necessary to restart them each time, but not in order with sound streaming servers. As soon as I restart my streaming server, this means that my users will experience a shutdown.

I tried to configure the hatch (ssh service for Twisted servers, you can enter and enter Python code in the console to do something), and connect to the console, restart the Python modules on the fly. It works sometimes, but it's hard to control. You never know how many instances of the old class exist on the server, and some of them may be difficult to access, and class relationships will be very complex. In addition, it may work in some situations, but sometimes you really need to restart the server, for example, you start the server with the selector reactor, and you want to start it with the epoll reactor instead, then you have to restart it. Another example, when the memory usage is too large, you must also restart them.

To build such a system, I had an idea, I think that it is possible to transfer these connections and data from the process to another. For instance:

We have a server called Broadcasting, and the working instance is under rev.123, and we want to replace it with rev.124.

Broadcasting rev.123 is running....
Startup Broadcasting rev.124 ....
Broadcasting rev.124 is stand by
Hand over connections from instance of rev.123 to instance of rev.124
Stop Broadcasting rev. 123 instance

Is it possible? I have no idea that the operating time of socket handles is related to processes or not, I thought that the sockets created by the process would be closed when the creation process was killed, but I'm not sure. If possible, are there any guidelines or articles to develop this kind of hot-code exchange mechanism? And is there something already done to achieve what I want for Twisted?

Thank.

+5
source share

All Articles