Ticket #233 (closed defect: fixed)

Opened 23 months ago

Last modified 23 months ago

Issue with Twisted threads

Reported by: thijs Owned by: thijs
Priority: major Milestone: 0.3
Component: Remoting Version: 0.3
Keywords: review Cc:
Fixed in revision: Branch:
Author:

Description (last modified by thijs) (diff)

I received this error while working on a Twisted .tac application.

File "buildbot.tac", line 2, in <module>
    from pyamf.remoting.gateway.twisted import TwistedGateway
  File "/Volumes/collab1/Sites/software/pyamf/pyamf/trunk/pyamf/remoting/gateway/twisted.py", line 17, in <module>
    threads = twisted.internet.threads
exceptions.AttributeError: 'module' object has no attribute 'threads'

Failed to load application: 'module' object has no attribute 'threads'

Even though it's available:

Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53) 
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import twisted.internet.threads
>>> 

My .tac:

from pyamf.remoting.gateway.twisted import TwistedGateway

from twisted.application import service, internet
from twisted.web import static, server, resource

def get_list(request):
    return filter(lambda x: not x.startswith('.'), os.listdir(r'%(basedir)s'))
    
def getWebService():
    '''
    Return a service suitable for creating an application object.

    This service is a simple web server that serves files on port 8080 from
    underneath the current working directory.
    '''
    
    # create a resource to serve static files
    root = resource.Resource()
    root.putChild('gateway', TwistedGateway({
        'smp.getList': get_list,
        'getList': get_list
    }))

    return internet.TCPServer(8080, server.Site(root))
    
application = service.Application('Test')

# attach the service to its parent application
web_service = getWebService()
web_service.setServiceParent(application)

I solved the problem by moving the p.r.g.TwistedGateway import into the def:

from twisted.application import service, internet
from twisted.web import static, server, resource

def get_list(request):
    return filter(lambda x: not x.startswith('.'), os.listdir(r'%(basedir)s'))
    
def getWebService():
    '''
    Return a service suitable for creating an application object.

    This service is a simple web server that serves files on port 8080 from
    underneath the current working directory.
    '''
    from pyamf.remoting.gateway.twisted import TwistedGateway

    # create a resource to serve static files
    root = resource.Resource()
    root.putChild('gateway', TwistedGateway({
        'smp.getList': get_list,
        'getList': get_list
    }))

    return internet.TCPServer(8080, server.Site(root))
    
application = service.Application('Test')

# attach the service to its parent application
web_service = getWebService()
web_service.setServiceParent(application)

So it looks like a import issue with our twisted module?

Attachments

233-twisted-import.diff Download (0.7 KB) - added by nick 23 months ago.
Better patch. All tests pass
233-test.diff Download (462 bytes) - added by thijs 23 months ago.

Change History

Changed 23 months ago by thijs

  • description modified (diff)

Changed 23 months ago by nick

  • keywords review added
  • status changed from new to accepted

Changed 23 months ago by nick

Better patch. All tests pass

Changed 23 months ago by nick

  • owner changed from nick to thijs
  • status changed from accepted to assigned

Changed 23 months ago by thijs

Changed 23 months ago by nick

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in r1147.

Note: See TracTickets for help on using tickets.