1238106Sdes.. _example_asynch:
2238106Sdes
3238106Sdes==============================
4238106SdesAsynchronous lookup
5238106Sdes==============================
6238106Sdes
7238106SdesThis example performs the name lookup in the background. 
8238106SdesThe main program keeps running while the name is resolved. 
9238106Sdes
10238106Sdes::
11238106Sdes
12238106Sdes	#!/usr/bin/python
13238106Sdes	import time
14238106Sdes	import unbound
15238106Sdes	
16238106Sdes	ctx = unbound.ub_ctx()
17238106Sdes	ctx.resolvconf("/etc/resolv.conf")
18238106Sdes	
19238106Sdes	def call_back(my_data,status,result):
20238106Sdes		print "Call_back:", my_data
21238106Sdes		if status == 0 and result.havedata:
22238106Sdes			print "Result:", result.data.address_list
23238106Sdes			my_data['done_flag'] = True
24238106Sdes	
25238106Sdes	
26238106Sdes	my_data = {'done_flag':False,'arbitrary':"object"}
27238106Sdes	status, async_id = ctx.resolve_async("www.seznam.cz", my_data, call_back, unbound.RR_TYPE_A, unbound.RR_CLASS_IN)
28238106Sdes	        
29238106Sdes	while (status == 0) and (not my_data['done_flag']):
30238106Sdes		status = ctx.process()
31238106Sdes		time.sleep(0.1)
32238106Sdes	
33238106Sdes	if (status != 0):
34238106Sdes		print "Resolve error:", unbound.ub_strerror(status)
35238106Sdes
36238106SdesThe :meth:`unbound.ub_ctx.resolve_async` method is able to pass on any Python object. In this example, we used a dictionary object `my_data`.
37