i***@zaleos.net
2018-10-10 10:54:16 UTC
I am trying to subclass Greenlet to provide a uniform interface for the
tests executed inside each of the greenlets. I checked gevent docs
<http://www.gevent.org/api/gevent.greenlet.html#subclassing-greenlet> and gevent
source code
<https://github.com/gevent/gevent/blob/master/src/gevent/greenlet.py#L216> and
attempted the following solution in order to measure overall execution time
of the greenlet:
from gevent import Greenlet
class MyGreenlet(Greenlet):
""" Tweak to properly store the args when this greenlet was created.
"""
def __init__(self, *args, **kwargs):
super(MyGreenlet, self).__init__(*args, **kwargs)
self._myargs = args
self._mykwargs = kwargs
self.duration = 0
self.func = None
# Custom _run() method to capture start/stop time
def _run(self, *args, **kwargs):
print('Run start')
start = time.time()
self.func(*args, **kwargs)
end = time.time()
self.duration = end - start
print('Run end')
def __setattr__(self, name, value):
if name == '_run':
self.func = value
When I attempt to execute above code, it fails with
AttributeError: 'MyGreenlet' object has no attribute 'func'
inside overriden _run() method when calling self.func(*args, **kwargs)
If I debug above code, I expect to see custom properties being added to the
object instance as the constructor executes, but that doesn't happen.
Feel like I'm missing something basic here. Any ideas?
tests executed inside each of the greenlets. I checked gevent docs
<http://www.gevent.org/api/gevent.greenlet.html#subclassing-greenlet> and gevent
source code
<https://github.com/gevent/gevent/blob/master/src/gevent/greenlet.py#L216> and
attempted the following solution in order to measure overall execution time
of the greenlet:
from gevent import Greenlet
class MyGreenlet(Greenlet):
""" Tweak to properly store the args when this greenlet was created.
"""
def __init__(self, *args, **kwargs):
super(MyGreenlet, self).__init__(*args, **kwargs)
self._myargs = args
self._mykwargs = kwargs
self.duration = 0
self.func = None
# Custom _run() method to capture start/stop time
def _run(self, *args, **kwargs):
print('Run start')
start = time.time()
self.func(*args, **kwargs)
end = time.time()
self.duration = end - start
print('Run end')
def __setattr__(self, name, value):
if name == '_run':
self.func = value
When I attempt to execute above code, it fails with
AttributeError: 'MyGreenlet' object has no attribute 'func'
inside overriden _run() method when calling self.func(*args, **kwargs)
If I debug above code, I expect to see custom properties being added to the
object instance as the constructor executes, but that doesn't happen.
Feel like I'm missing something basic here. Any ideas?
--
You received this message because you are subscribed to the Google Groups "gevent: coroutine-based Python network library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gevent+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "gevent: coroutine-based Python network library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gevent+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.