Changeset 278

Show
Ignore:
Timestamp:
08/11/06 12:12:49 (2 years ago)
Author:
mj
Message:

Use the new exceptions, wait for the IDE to connect, and don't bother with closing the IDE connection on a thread

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • z3wingdbg/trunk/wingdebugservice.py

    r242 r278  
     1import time 
     2 
    13from zope import component, interface 
     4from zope.i18nmessageid import MessageFactory 
    25 
    36from zope.app.component.hooks import getSite 
     
    58from interfaces import IWingDebugService, IWingConfiguration 
    69from interfaces import IDebugServerConfiguration, INetworkDebuggerFactory 
    7 from interfaces import IDebugServerFactory 
     10from interfaces import IDebugServerFactory, DebugServerStartError 
     11from interfaces import IDEConnectionError 
     12 
     13_ = MessageFactory('z3wingdbg') 
    814 
    915class WingDebugService(object): 
     
    1723            return 
    1824        site = getSite() 
     25         
    1926        config = component.getUtility(IWingConfiguration, context=site) 
    20         serverconfig = component.getUtility(IDebugServerConfiguration, 
    21                                             config.serverType, context=site) 
     27        serverconfig = component.queryUtility(IDebugServerConfiguration, 
     28                                              config.serverType, context=site) 
     29        if not serverconfig: 
     30            raise DebugServerStartError( 
     31                _(u'debugserver-config-not-found' 
     32                  u'Could not find any configuration for the ${serverType} ' 
     33                  u'debug server', dict(serverType=config.serverType))) 
     34         
    2235        debuggerFactory = component.getUtility(INetworkDebuggerFactory) 
    23         serverFactory = component.getUtility(IDebugServerFactory,  
    24                                              config.serverType) 
    25         self.debugger = debuggerFactory(config) 
     36        serverFactory = component.queryUtility(IDebugServerFactory,  
     37                                               config.serverType) 
     38        if not serverFactory: 
     39            raise DebugServerStartError( 
     40                _(u'debugserver-factory-not-found' 
     41                  u'Could not find a factory for the ${serverType} ' 
     42                  u'debug server', dict(serverType=config.serverType))) 
     43         
     44        try: 
     45            self.debugger = debuggerFactory(config) 
     46        except RuntimeError, exception: 
     47            raise DebugServerStartError(_(u'wingdebug-already-running', 
     48                                          unicode(exception))) 
     49        except ValueError: 
     50            raise DebugServerStartError(_( 
     51                u'winghome-incorrect', 
     52                u'The Wing debug libraries could not be loaded, please verify ' 
     53                u'your configured Wing Home')) 
     54         
    2655        self.server = serverFactory(serverconfig, self.debugger) 
    2756     
     
    3968        if not self.debugServerRunning or self.connectedToIDE: 
    4069            return 
    41         self.server.runInDebugContext(self.debugger.connectClient) 
     70         
     71        connected = [] 
     72        def connectClient(): 
     73            self.debugger.connectClient() 
     74            connected.append(self.debugger.clientConnected) 
     75        self.server.runInDebugContext(connectClient) 
     76         
     77        # time out the call, up to 5 seconds 
     78        timeout = time.time() + 5 
     79        while time.time() < timeout and not connected: 
     80            time.sleep(0.05) 
     81        if not connected or not connected[0]: 
     82            message = _(u'ide-connection-failure', 
     83                        u'Failed to connect to the IDE. Check your IDE host ' 
     84                        u'and port are correct.') 
     85            if connected: 
     86                message = _(u'ide-connection-timeout', 
     87                            u'Connection to IDE timed out') 
     88            raise IDEConnectionError(message) 
    4289     
    4390    def disconnectIDE(self): 
    4491        if not (self.debugServerRunning and self.connectedToIDE): 
    4592            return 
    46         self.server.runInDebugContext(self.debugger.disconnectClient) 
     93        # Call disconnect from the current thread. Not entirely thread-safe, 
     94        # but with multiple calls to disconnectClient, we at the worst get 
     95        # exceptions from an already cleared __fChannel. 
     96        try: 
     97            self.debugger.disconnectClient() 
     98        except: 
     99            pass 
    47100     
    48101    @property