Skip to content

Instantly share code, notes, and snippets.

@caryhaynie
Created April 6, 2011 13:23
Show Gist options
  • Select an option

  • Save caryhaynie/905625 to your computer and use it in GitHub Desktop.

Select an option

Save caryhaynie/905625 to your computer and use it in GitHub Desktop.
Python class to marshall functions across threads.
from collections import deque
class Dispatcher(object):
_queue = deque()
@staticmethod
def dispatch(func):
Dispatcher._queue.appendleft(func)
@staticmethod
def process():
try:
func = Dispatcher._queue.pop()
func()
except IndexError:
pass
return True
@staticmethod
def register_glib():
try:
import glib
glib.idle_add(Dispatcher.process)
except ImportError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment