Last active
January 2, 2016 01:09
-
-
Save devdazed/8228159 to your computer and use it in GitHub Desktop.
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
class Result(threading.Event): | |
exception = None | |
def execute(): | |
cql = 'select * from events limit 10' | |
response = Result() | |
def _on_error(error): | |
response.exception = error | |
response.set() | |
def _on_complete(results): | |
try: | |
do_something(results) | |
except BaseException as exc: | |
response.exception = exc | |
finally: | |
response.set() | |
future = session.execute_async(cql) | |
future.add_callbacks(_on_results, _on_error) | |
return response | |
def main(): | |
result = execute() | |
result.wait() | |
if result.exception: | |
raise result.exception |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment