rexec, threads, and ugly crashes
Danyel Fisher
danyelf at severus-alexander.ics.uci.edu
Fri Apr 20 15:54:31 EDT 2001
mysteries within mysteries!
I started stripping away code to find the absolute
minimum that displays this phenomenon, and wound up
with 35 lines of joy.
For me, if I run this, then open a telnet session,
the code will crash. It won't actually core dump,
but it will complain that the interpreter is not
initialized.
If I change one line--if I set the server to
"serve_forever"--everything works fine. Now,
all that serve_forever DOES is repeatedly call
"handle_request"
This is nonintuitive behvior, to me. What am I
missing?
Danyel
---
import SocketServer
class SMTPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
def server_bind(self):
"""
Connects to a server. Pulled off of some web site's info
on how to ensure that socket can be (re)used.
"""
import socket
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
SocketServer.TCPServer.server_bind(self)
class SMTPHandler(SocketServer.StreamRequestHandler):
"""
"""
exec_env = None
def handle(self):
print "ok"
import rexec
if self.exec_env is None:
print "ABOUT TO START REXEC INIT"
exec_env = rexec.RExec()
print "FINSIHED REXEC INTI"
# MAIN MODULE
if __name__=='__main__':
# Create an instance of our server class
port = 1999
import socket
server=SMTPServer(('', port), SMTPHandler)
print "Server initted on port",port
server.handle_request()
# server.serve_forever()
print ">>Stopped."
More information about the Python-list
mailing list