Improve doc and debug about greenlets hell

This commit is contained in:
boyska 2016-07-18 15:54:22 +02:00
parent bae09d70f7
commit 3229330cfc
4 changed files with 34 additions and 8 deletions

View file

@ -93,6 +93,7 @@ class EventSource(ParentedLet):
class Monitor(ParentedLet):
'''Manages timegenerators and audiogenerators'''
def __init__(self, parent_queue, conf):
ParentedLet.__init__(self, parent_queue)
self.log = logging.getLogger(self.__class__.__name__)
@ -100,6 +101,7 @@ class Monitor(ParentedLet):
self.running = {}
self.conf = conf
self.source = EventSource(self.q, uri=conf['DB_URI'])
self.source.parent_greenlet = self
def add(self, timespec, audiospec):
'''
@ -125,15 +127,21 @@ class Monitor(ParentedLet):
audiogen = gevent.spawn_later(delta.total_seconds(), audiogenerate,
audiospec)
audiogen.parent_greenlet = self
audiogen.doc = 'Will wait {} seconds, then generate audio "{}"'.format(
delta.total_seconds(),
audiospec.get('nick', ''))
self.running[timespec.eid] = {
'greenlet': audiogen,
'running_time': datetime.now() + timedelta(
seconds=delta.total_seconds()),
'audiospec': audiospec
}
gevent.spawn_later(delta.total_seconds(),
self.source.reload_id,
timespec.eid)
gl = gevent.spawn_later(delta.total_seconds(),
self.source.reload_id,
timespec.eid)
gl.parent_greenlet = self
gl.doc = 'Will wait, then reload id {}'.format(timespec.eid)
# FIXME: audiogen is ready in a moment between
# exact_time - CACHING_TIME and the exact_time
# atm we are just ignoring this "window", saying that any moment is

View file

@ -12,6 +12,7 @@ class ParentedLet(gevent.Greenlet):
def __init__(self, queue):
gevent.Greenlet.__init__(self)
self.parent_queue = queue
self.parent_greenlet = None
self.tracker = None # set this to recognize easily
def parent_msg(self, kind, *args):
@ -54,6 +55,7 @@ class CeleryTask(ParentedLet):
class Timer(ParentedLet):
'''wait some time, then send a "timer" message to parent'''
def __init__(self, milliseconds, queue):
ParentedLet.__init__(self, queue)
self.ms = milliseconds

View file

@ -77,8 +77,12 @@ class Player(gevent.Greenlet):
mpd_client.addid(song, insert_pos)
def _run(self):
MpcWatcher(self.q, self.conf, client=None).start()
Timer(int(self.conf['CHECK_SECS']) * 1000, self.q).start()
mw = MpcWatcher(self.q, self.conf, client=None)
mw.parent_greenlet = self
mw.start()
t = Timer(int(self.conf['CHECK_SECS']) * 1000, self.q)
t.parent_greenlet = self
t.start()
# at the very start, run a check!
gevent.Greenlet.spawn(self.check_playlist)
while True:

View file

@ -58,11 +58,23 @@ def rpc_wip():
greenlets = []
for ob in filter(lambda obj: isinstance(obj, greenlet),
gc.get_objects()):
greenlets.append({
objrepr = {
'repr': repr(ob),
'class': ob.__class__.__name__,
'parent': repr(ob.parent)
})
}
if hasattr(ob, 'parent_greenlet') and ob.parent_greenlet is not None:
objrepr['parent'] = hex(id(ob.parent_greenlet))
else:
objrepr['parent'] = hex(id(ob.parent)) if ob.parent is not None else None
if hasattr(ob, 'doc'):
objrepr['doc'] = ob.doc.split('\n')[0]
elif ob.__doc__:
objrepr['doc'] = ob.__doc__.split('\n')[0]
greenlets[hex(id(ob))] = objrepr
# TODO: make it a tree
return jsonify(dict(greenlets=greenlets,
audiogens=get_scheduled_audiogen(),
))