同じクラスにいくつかの論理プロセスを実装しています。クラスインスタンスは、プロセスごとにジェネレーターを取得し、そのジェネレーターをrun()
進めます。私の場合、ジェネレーターは終了しません。
以下のコードでfoo_functionとfoo_objectをどのように呼び出しますか?
class C(threading.Thread):
def foo_function(self):
""" generator *function*,
logical process foo """
while True:
# some state checks
if self.some_attr:
# side-effects here
pass
yield
def __init__(self):
# generator *object*
# i.e. process instance
self.foo_object = self.foo_function() # <- here
def run(self):
while True:
next(self.foo_object)
next(self.another_object)
if xxx:
next(self.yet_another_object)
典型的なプロセスは、、、discovery
などauthentication
ですwatchdog
。
ジェネレーターとジェネレーター オブジェクトを含む属性を適切な方法で定義する関数に名前を付けるにはどうすればよいですか?
最後に、同じ名前の名前は非常識ですよね?
class C:
def foo(self):
yield 1; yield 2
def __init__(self):
self.foo = self.foo()
c = C()
type(C.foo) is function
type(c.foo) is generator