[Twisted-Python] Bootstrapping Servers

Grant McDonald gmcdonald at infocomp.com
Thu Mar 24 01:23:04 EST 2005


Dear All,

I have created some code to close all active connections to a server, spawn
a new instance of itself and call reactor.stop() to facilitate a remote
bootstrap restart of a server. The bootstrapping process takes place through
a loader where if passed an option to bootstrap the code pauses for 20 secs
to allow the previous process to exit:

import sys

if sys.argv[1] == "--bootstrap" or sys.argv[1] == "-b":
    print 'bootstrapping'
    del sys.argv[1]
    import time
    time.sleep(20.0)

from twisted.python.runtime import platformType
if platformType == "win32":
    from twisted.scripts.twistw import run
else:
    from twisted.scripts.twistd import run

run()

However the above code does not allow the server to start since twistd
complains that the port is in use:

2005/03/24 17:14 AUS Eastern Daylight Time [-] Log opened.
2005/03/24 17:14 AUS Eastern Daylight Time [-] twistd 1.3.0
(C:\Python23\python.exe 2.3.3) starting up
2005/03/24 17:14 AUS Eastern Daylight Time [-] reactor class:
twisted.internet.default.SelectReactor
2005/03/24 17:14 AUS Eastern Daylight Time [-] managers.ConnectionManager
starting on 12005
2005/03/24 17:14 AUS Eastern Daylight Time [-] Traceback (most recent call
last):
2005/03/24 17:14 AUS Eastern Daylight Time [-]   File "D:\python
projects\programs\zcfscheduler\loader.py", line 15, in ?
2005/03/24 17:14 AUS Eastern Daylight Time [-]     run()

<-- snip -->

2005/03/24 17:14 AUS Eastern Daylight Time [-]     return getattr(reactor,
'listen'+self.method)(*self.args, **self.kwargs)
2005/03/24 17:14 AUS Eastern Daylight Time [-]   File
"C:\Python23\lib\site-packages\twisted\internet\default.py", line 283, in
listenTCP
2005/03/24 17:14 AUS Eastern Daylight Time [-]     p.startListening()
2005/03/24 17:14 AUS Eastern Daylight Time [-]   File
"C:\Python23\lib\site-packages\twisted\internet\tcp.py", line 594, in
startListening
2005/03/24 17:14 AUS Eastern Daylight Time [-]     raise CannotListenError,
(self.interface, self.port, le)
2005/03/24 17:14 AUS Eastern Daylight Time [-]
twisted.internet.error.CannotListenError: Couldn't listen on any:12005:
(10048, 'Address already in use').

how can i get the server to stop, restart itself and release the port in the
process?

Regards,

Grant McDonald

Important notice: This message is intended for the individual(s) and entity(s) addressed. The information contained in this transmission and any attached, may be confidential and may also be the subject of legal privilege, public interest immunity or legal professional privilege. Any review, retransmission, dissemination or other use of, taking of any action in reliance upon this information by person or entities other than the recipient is prohibited and requires authorization from the sender. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person) you may not copy or deliver this message to anyone. In such cases you should destroy this message and kindly notify the sender by reply email. 

WARNING: Although Infocomp has taken reasonable precautions so that no viruses are present in this e-mail, the company cannot accept responsibility for any loss or damage arising from the use of e-mail attachments.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20050324/694c5fa3/attachment.htm 


More information about the Twisted-Python mailing list