Commit 4d5f888e authored by Denis Bilenko's avatar Denis Bilenko

Greenlet: use _formatinfo() method rather than _formatted_info property

parent 3e375b6c
No related merge requests found
...@@ -170,13 +170,16 @@ class Greenlet(greenlet): ...@@ -170,13 +170,16 @@ class Greenlet(greenlet):
def __repr__(self): def __repr__(self):
classname = self.__class__.__name__ classname = self.__class__.__name__
result = '<%s at %s' % (classname, hex(id(self))) result = '<%s at %s' % (classname, hex(id(self)))
formatted = self._formatted_info formatted = self._formatinfo()
if formatted is not None: if formatted:
result += ': ' + formatted result += ': ' + formatted
return result + '>' return result + '>'
@lazy_property def _formatinfo(self):
def _formatted_info(self): try:
return self._formatted_info
except AttributeError:
pass
try: try:
result = getfuncname(self.__dict__['_run']) result = getfuncname(self.__dict__['_run'])
except Exception: except Exception:
...@@ -189,7 +192,10 @@ class Greenlet(greenlet): ...@@ -189,7 +192,10 @@ class Greenlet(greenlet):
args.extend(['%s=%r' % x for x in self.kwargs.items()]) args.extend(['%s=%r' % x for x in self.kwargs.items()])
if args: if args:
result += '(' + ', '.join(args) + ')' result += '(' + ', '.join(args) + ')'
# it is important to save the result here, because once the greenlet exits '_run' attribute will be removed
self._formatted_info = result
return result return result
return ''
@property @property
def exception(self): def exception(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment