Skip to content

Instantly share code, notes, and snippets.

@devdazed
Last active January 2, 2016 01:09
Show Gist options
  • Save devdazed/8228159 to your computer and use it in GitHub Desktop.
Save devdazed/8228159 to your computer and use it in GitHub Desktop.
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