I have a few logical processes implemented in the same class.
A class instance get a generator for each process, and run()
advances said generators. In my case generators don't end.
How would you call foo_function and foo_object in the code below
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)
Typical processes are discovery
, authentication
, watchdog
, etc.
How can I name function that defines the generator and the attribute that contains generator object in a sensible way?
Finally just for the kicks, same name name would be insane, right?
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