Opened 10 years ago

Closed 10 years ago

#2932 defect closed duplicate (duplicate)

I get this error repeatably doing a simple web page read more than once.

Reported by: jackmullen Owned by:
Priority: high Milestone: Web-0.7
Component: core Keywords: unsubscriptable
Cc: Branch:
Author:

Description (last modified by Jean-Paul Calderone)

Traceback (most recent call last):
  File "C:\python\webclasses_test.py", line 71, in <module>
    webdata.append(webAccess.getPage('getFolders'))
  File "C:\python\webclasses_test.py", line 44, in getPage
    reactor.run()
  File "C:\Python25\lib\site-packages\twisted\internet\posixbase.py", line 220, in run
    self.mainLoop()
  File "C:\Python25\lib\site-packages\twisted\internet\posixbase.py", line 228, in mainLoop
    self.runUntilCurrent()
--- <exception caught here> ---
  File "C:\Python25\lib\site-packages\twisted\internet\base.py", line 561, in runUntilCurrent
    call.func(*call.args, **call.kw)
  File "C:\Python25\lib\site-packages\twisted\internet\base.py", line 411, in _continueSystemEvent
    for callList in sysEvtTriggers[1], sysEvtTriggers[2]:
exceptions.TypeError: 'NoneType' object is unsubscriptable

The code that produces this error is as a follows.

Note that simply by using an outside of class callback the code generates the error. Apparently calling reactor.stop() does not work! Is there any way to make something as simple as a class that can stay alive and be used to contact a web page more than once work?

# -*- coding: iso-8859-1 -*- 
from twisted.web import client
from twisted.internet import reactor
import sys

class getWebData():

#test for functionality
#later the class would contain a dictionary of addressable pages
    getFolders='http://www.yahoo.com'

    def __init__(self, dictWebResponse,callback):
        self.dictWebResponse=dictWebResponse
        self.complete=0
        self.callback=callback
        
        print "web class setup"
        
    def actionComplete(self):
        return self.complete

    def storeData(self,data):
        reactor.stop()
        self.complete=1
        print data
        self.data=data
        self.callback()
        
    
    def printError(self,failure):
        print  "WebClass Error:" ,failure.getErrorMessage()
        reactor.stop()
        
    def nextPage(self):    
        client.getPage(self.getFolders)
        
    def getPage(self,choice):
        print choice
        if choice=='getFolders':
            print self.getFolders
            client.getPage(self.getFolders).addCallback(
                self.storeData).addErrback(
                self.printError)
            reactor.run()
        
    def getData(self):
        return self.data
#end getWebData

#concept multiple objects that can be used to get real time content
#This fails even if just accessed directly more than one time


di={}
webdata=[]
lcount=2




def callback():
    print "finished %d" %lcount
    lcount=lcount-1
    if lcount > -1:
        print "stopped"
#even with this next line out . It still fails. It will also fail without the outside
#call back if you place the code under a button and refire the button to access the
#same site twice.
        #webdata.append(webAccess.getPage('getFolders'))

print lcount

webAccess=getWebData(di,callback)
webdata.append(webAccess.getPage('getFolders'))

Change History (3)

comment:1 Changed 10 years ago by Jean-Paul Calderone

Description: modified (diff)

Reformatting description.

comment:2 Changed 10 years ago by Jean-Paul Calderone

Cc: TypeError: removed
Resolution: duplicate
Status: newclosed

This is basically a duplicate of #1485. The underlying problem here, though, is that reactors are not restartable. You cannot call reactor.run() after you have called reactor.stop().

The code needs to be structured such that the reactor is not stopped until all of the work the process needs to do using Twisted is done. That means make both of your getPage calls before calling reactor.stop().

comment:3 Changed 7 years ago by <automation>

Owner: Glyph deleted
Note: See TracTickets for help on using tickets.