Last active
August 29, 2015 14:22
-
-
Save prologic/f95e2fe451b5a8eccfa9 to your computer and use it in GitHub Desktop.
In response to http://emptysqua.re/blog/tornado-locks-and-queues/
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
#!/usr/bin/env python | |
from __future__ import print_function | |
from circuits import Component, Debugger, Event | |
class condition(Event): | |
"""condition Event""" | |
class waiter(Event): | |
"""waiter Event""" | |
class notifier(Event): | |
"""notifier Event""" | |
class App(Component): | |
def started(self, *args): | |
self.fire(waiter()) | |
yield | |
self.fire(notifier()) | |
yield | |
raise SystemExit(0) | |
def waiter(self): | |
print("I'll wait right here") | |
yield self.wait("condition") | |
print("I'm done waiting") | |
def notifier(self): | |
print("About to notify") | |
self.fire(condition()) | |
print("Done notifying") | |
def generate_events(self, event): | |
print(".") | |
event.reduce_time_left(0.1) | |
(App() + Debugger()).run() |
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
#!/usr/bin/env python | |
from __future__ import print_function | |
from circuits import Component, Debugger, Event | |
class producer(Event): | |
"""producer Event""" | |
class work(Event): | |
"""work Event""" | |
class Consumer(Component): | |
def work(self, i): | |
print("Doing work on {0:d}".format(i)) | |
# XXX: We don't have an asynchronous sleep() :) | |
class App(Component): | |
def started(self, *args): | |
Consumer().register(self) | |
self.fire(producer()) | |
yield | |
raise SystemExit(0) | |
def producer(self): | |
for i in range(4): | |
self.fire(work(i)) | |
print("Put {0:d}".format(i)) | |
(App() + Debugger()).run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo of
test_queue
: