Tkinter+python threads problem while mutilating IDLE...

dj trombley worldwin at liii.com
Fri Dec 17 00:22:28 EST 1999


Hello, Greg here...

First of all, the question I'm posing is: Why does the attached code
crash and is there any way to work around the problem? 

Now, a little explanation... The code is a hack which is supposed to
cause IDLE, when IDLE is started with a filename on the commandline, to
check for an instance of IDLE and have the file loaded in the currently
running instance. It doesn't modify any existing IDLE source files -
it's a replacement for idle.py It's not clever... 

The problem is that when the 'server' receives the command line from the
new, 'client', IDLE instance, it tries to open the requested files and
locks up. We think that the problem is with python threading and have
run out of ideas. Can anybody offer any clues?

Greg Velichansky, Dave Trombley
-------------- next part --------------
#! /usr/bin/env python
import PyShell
from socket import *
from select import *
from thread import *
from cPickle import *
import sys
import traceback

class AmIHere:
    def __init__(self):
        try:
            self.sock = socket(AF_INET, SOCK_STREAM)
            self.addr = gethostbyaddr("localhost")
            try:
                self.sock.connect((self.addr[2][0], 7781))
            	self.prevInst = 1
            except:
                traceback.print_exc()
                self.prevInst = 0
                try:
                    self.sock.shutdown(2)
                except:
                    pass
                self.sock = socket(AF_INET, SOCK_STREAM)
                	            
            if not self.prevInst:
                self.sock.bind((self.addr[2][0], 7781))
                self.sock.listen(3)
                start_new_thread(self.server, ())
                PyShell.main()
                return
            else:
                try:
                    cmdstr = dumps(sys.argv)
                    self.sock.send(cmdstr)
                except:
                    PyShell.main()
                    return
                return
        except:
            traceback.print_exc()
            PyShell.main()
            return
            
    def server(self):
        try:
            while(1):
                print(str(select([self.sock],[],[])))
                con = self.sock.accept()
                cmdstr = con[0].recv(4096)
                filelist = loads(cmdstr)
                print str(filelist)
                for i in filelist[1:]:  
                    PyShell.flist.open(i)
                    aPath = os.path.abspath(os.path.dirname(i))
                    if not aPath in sys.path:
                        sys.path.insert(0, aPath)
                else:
                    aPath = os.getcwd()
                    if not aPath in sys.path:
                        sys.path.insert(0, aPath)
 	except:
 		# Note:  Remove this.  It breaks.
 		traceback.print_exc()       
            
        
AmIHere()


More information about the Python-list mailing list