Skip to content

Commit

Permalink
little readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Grayson Koonce committed Jul 12, 2015
1 parent fcceddd commit 9aac15c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
# threadloop
# ThreadLoop

[![Build Status](https://travis-ci.org/breerly/threadloop.svg?branch=master)](https://travis-ci.org/breerly/threadloop) [![Coverage Status](https://coveralls.io/repos/breerly/threadloop/badge.svg)](https://coveralls.io/r/breerly/threadloop)

> Run Tornado Coroutines from Synchronous Python.
```python

from threadloop import ThreadLoop
from tornado import gen

@gen.coroutine
def hello(greeting="Goodbye"):
raise gen.Result("%s World" % greeting)

with ThreadLoop() as threadloop:
future = threadloop.submit(hello, "Hello")

print future.result() # Hello World
```
6 changes: 3 additions & 3 deletions threadloop/threadloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ def stop(self):
self.io_loop.stop()
self.thread.join()

def submit(self, coroutine, *args, **kwargs):
def submit(self, fn, *args, **kwargs):
"""Submit Tornado Coroutine to IOLoop in daemonized thread.
:param coroutine: Tornado Coroutine to execute
:param fn: Tornado Coroutine to execute
:param args: Args to pass to coroutine
:param kwargs: Kwargs to pass to coroutine
:returns concurrent.futures.Future: future result of coroutine
Expand All @@ -80,7 +80,7 @@ def on_done(tornado_future):
future.set_result(tornado_future.result())

self.io_loop.add_callback(
lambda: coroutine(*args, **kwargs).add_done_callback(on_done)
lambda: fn(*args, **kwargs).add_done_callback(on_done)
)

return future

0 comments on commit 9aac15c

Please sign in to comment.