summaryrefslogtreecommitdiff
path: root/examples/introspection/python/query-async.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/introspection/python/query-async.py')
-rwxr-xr-xexamples/introspection/python/query-async.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/introspection/python/query-async.py b/examples/introspection/python/query-async.py
new file mode 100755
index 000000000..be5ede51b
--- /dev/null
+++ b/examples/introspection/python/query-async.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+import gi
+from gi.repository import Tracker, GObject
+
+def results_ready_cb (obj, result, user_data):
+ cursor = obj.query_finish (result)
+
+ # This can also be done asynchronously
+ while (cursor.next (None)):
+ print cursor.get_string (0)
+
+ user_data.quit ()
+
+
+if __name__ == "__main__":
+ loop = GObject.MainLoop ()
+
+ # The connection can be requested asynchronously
+ conn = Tracker.SparqlConnection.get (None)
+ conn.query_async ("SELECT ?u WHERE { ?u a nie:InformationElement. }",
+ None,
+ results_ready_cb,
+ loop)
+
+ loop.run ()