Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.015 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'executed': 0.09; 'subject:How': 0.10; 'python': 0.11; 'def': 0.12; '2.7': 0.14; 'prevent': 0.16; 'import': 0.22; 'to:name:python-list@python.org': 0.22; 'print': 0.22; '(a)': 0.24; 'question': 0.24; 'message- id:@mail.gmail.com': 0.30; 'subject:that': 0.31; 'linux': 0.33; 'running': 0.33; 'subject:the': 0.34; 'received:google.com': 0.35; 'module.': 0.36; 'seconds': 0.37; 'same.': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=iIkx1I8dAIb2olgaIHAzK62IDK9lkS8nHtN/hGWpTdA=; b=ES4D5pSJ4/zbgENHJ8QUlHusbk1TZ8NUiK+QG1GFZpPnpOMftu8MiMw2eXSXPpYotZ YFjDBQQTVhxcHg92Jg8q80Zr4xd2e4slag+ez6aU0nPRDZst0i05MFn9gxa6jq6wTcE/ ZiR4W7h6aobigU8YyLTLCuaW044r9rzthAyMREWO4WNxtQHRN6CT66PsI/m3eHtZvIkG TXn1DBL3w+eeOz1aEpUDwPm4vPqMQeV+9CD6fyqjTUG0+phxrVGyaFmVX3sn8OYejoJg ren4ZQ8xgz+wfs6Zluf8DUyWmqLkXfj74GuXhoaK/ZSvQKZq7qXotPT1PgTN/wF1dILQ leow== MIME-Version: 1.0 X-Received: by 10.112.119.167 with SMTP id kv7mr3923746lbb.62.1421240842316; Wed, 14 Jan 2015 05:07:22 -0800 (PST) Date: Wed, 14 Jan 2015 18:37:22 +0530 Subject: How to terminate the function that runs every n seconds From: Ganesh Pal To: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1421240850 news.xs4all.nl 2927 [2001:888:2000:d::a6]:42202 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83749 Iam using Linux and Python 2.7 and playing with the threading.Timer module. I had the below question on the same. (a) How to I prevent the execution the "EXECUTED SLEEP" after 4 seconds ? , current this is running in an infinite loop node-1# cat file_01.py import threading import time def printit(): threading.Timer(2, printit).start() print "EXECUTED SLEEP" printit() print "hi" time.sleep(4) print "hi" time.sleep(5) Output: node-1# python file_01.py EXECUTED SLEEP hi EXECUTED SLEEP EXECUTED SLEEP EXECUTED SLEEP Regards, Ganesh