#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    6
    Rep Power
    0

    Function self call- ok?


    I am new to python. I am using python to check my gmail account for newly arrived messages. I want it to constantly check it every 10 seconds, for example. Is this function ok practice? Is there another way to do the perpetual check? Would it be better to use a while loop with an input exit strategy?

    Code:
    def checkMail(old,new):
        now = int(g.get_mail_count())
        curr = now - old
        if curr > new:
            new = curr
            print "NEW"
        time.sleep(10)
        checkMail(old,new)
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,841
    Rep Power
    480
    Recursive functions are ok----BUT THEY NEED A WAY TO TERMINATE. You need to terminate the recursion. So no, your function will fill the stack after a while and crash.

    Rewrite with a
    while True:
    loop.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo