我想为gevent greenlet分配一个自定义名称/标识符。Gevent已经分配了一个唯一的名称:
def name(self):
"""
The greenlet name. By default, a unique name is constructed using
the :attr:`minimal_ident`. You can assign a string to this
value to change it. It is shown in the `repr` of this object.
.. versionadded:: 1.3a2
"""
但是,我不知道如何将此值更改为用户输入的名称。有可能吗?你知道吗
我尝试这样做,结果出现属性错误:
def begin(self):
self.thread = gevent.spawn(self.print_message)
self.thread.minimal_ident = "t1"
print(self.thread.name)
AttributeError: attribute 'minimal_ident' of
'gevent._greenlet.Greenlet' objects is not writable
gevent.Greenlet.name
不是常见的property
,而是gevent.util.readproperty
对象,即a special non-data descriptor与@property
类似,对于非数据描述符:您可以简单地覆盖它:
阅读关于gevent源代码和the descriptor doc的更多信息。你知道吗
先实例化类,然后重写方法
这将用您自己的字符串替换构造的名称。你知道吗
相关问题 更多 >
编程相关推荐