Created
April 6, 2011 13:23
-
-
Save caryhaynie/905625 to your computer and use it in GitHub Desktop.
Python class to marshall functions across threads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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