-_idles = []
-def _runidles():
- """Invoke the functions on the idles queue."""
- global _idles
- while _idles:
- old = _idles
- _idles = []
- for func, args, kw in old:
- try:
- func(*args, **kw)
- except:
- uncaught()
- return False
-
-def idly(func, *args, **kw):
- """Invoke FUNC(*ARGS, **KW) at some later point in time."""
- if not _idles:
- GO.idle_add(_runidles)
- _idles.append((func, args, kw))
-
-_asides = T.Queue()
-def _runasides():
- """
- Coroutine function: reads (FUNC, ARGS, KW) triples from a queue and invokes
- FUNC(*ARGS, **KW)
- """
- while True:
- func, args, kw = _asides.get()
- try:
- func(*args, **kw)
- except:
- uncaught()
-
-def aside(func, *args, **kw):
- """
- Arrange for FUNC(*ARGS, **KW) to be performed at some point in the future,
- and not from the main coroutine.
- """
- idly(_asides.put, (func, args, kw))
-