cherrypy: I try to have multiple instances of a plugin. I try to read the class attributes of these instances as following:
class fooPlugin(plugins.SimplePlugin):
def __init__(self, bus, bar):
plugins.SimplePlugin.__init__(self, bus)
self.bar = bar
if __name__ == '__main__':
cherrypy.config.update({'server.socket_host': serverIp, #test.local',
'server.socket_port': serverPort,
})
conf = {
'/': {
'tools.staticdir.on': True,
'tools.staticdir.root': serverRoot,
'tools.staticdir.dir': staticDir,
'tools.staticdir.index': staticFile,
}
}
x=fooPlugin(cherrypy.engine, 4).subscribe()
y=fooPlugin(cherrypy.engine, 8).subscribe()
print(x.bar)
File "...", line ..., in <module>
print(x.bar)
AttributeError: 'NoneType' object has no attribute 'bar'
What is the correct way to set a class attribute for a plugin with cherrypy?
Pleas help... Thank you...
- CherryPy version: 18.8.0
- Python version: 3.9.2
- OS: Raspian
xdoesn't contain thefooPlugininstance, it contains the value thatsubscribe()returned. Since it doesn't return anything, you're settingxtoNone.Split up the assignment and the call to
subscribe():