When using the following code only for demonstrative purposes:
from uuid import uuid4
class router(object):
def route(self):
res = response(jid=str(uuid4()))
worker = resource()
worker.dispatch(res)
print '[jid: %s, status: %s]' % (res.jid, res.status)
class response(object):
def __init__(self, jid):
self.jid = jid
self.status = 0
class resource(object):
def __init__(self):
self.status = 200
def dispatch(self, res):
res.status = self.status
rs = 'ok'
#return rs
yield rs
app = router()
app.route()
If using return rs
instead of yield rs
I can update the value of status within the dispatch(self, res
) method of the resource class, out put is something like:
[jid: 575fb301-1aa9-40e7-a077-87887c8be284, status: 200]
But if using yield rs
I can't update the value of status, I am getting always the original value, example:
[jid: 575fb301-1aa9-40e7-a077-87887c8be284, status: 0]
Therefore I would like to know, how to update the object variables of an object passed as a reference, when using yield.