Custom wait in appium ios python

I have created a custom wait function for appium for iOS automation in python. My script is like :

def wait(element):
global wd
html_source = wd.page_source
if element not in html_source:
WebDriverWait(wd, 20).until(EC.presence_of_element_located((By.NAME, element)))
print"element not found"

but when I run this function and when an element is not found, it wont print the error message.

Also If I want to iterate the search for 5 times and finally want to print the result, what should i need to do ???

Please help