Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'algorithm': 0.04; 'see:': 0.07; 'assuming': 0.09; 'builtin': 0.09; 'function,': 0.09; 'means,': 0.09; 'operator,': 0.09; 'python': 0.11; 'assume': 0.14; '2.7': 0.14; '0):': 0.16; 'parentheses': 0.16; 'precedence': 0.16; 'precedence.': 0.16; 'received:74.208.4.195': 0.16; 'simplified': 0.16; 'wrote:': 0.18; 'print': 0.22; 'header:User-Agent:1': 0.23; "shouldn't": 0.24; 'subject:/': 0.26; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'code': 0.31; 'url:python': 0.33; 'period': 0.33; 'problem': 0.35; 'problem.': 0.35; 'but': 0.35; 'really': 0.36; 'i.e.': 0.36; "didn't": 0.36; 'hi,': 0.36; 'url:org': 0.36; 'hat': 0.38; 'version,': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; '5th': 0.60; 'fire': 0.65; 'minutes': 0.67; 'sample': 0.67; 'received:74.208': 0.68; 'discovered': 0.83; 'min': 0.84; 'url:reference': 0.84; 'approach.': 0.91 Date: Thu, 06 Jun 2013 20:43:11 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: python-list@python.org Subject: Re: trigger at TDM/2 only References: <46d8c42f-fdfd-49a5-96e8-ec53d5e599d5@googlegroups.com> In-Reply-To: <46d8c42f-fdfd-49a5-96e8-ec53d5e599d5@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:eA5yVH5vaZQCZ3lkr6eNUIH/Yexe2joaLTry2Y2wGZ4 NwoAChZlrE8j9YKfCrMIwPS5pH9yh5D52lgfidskfxoH6i1cTR y6l9mv9Z4poViYM/C3glMbCa+WRzmZEpYxyLVdCmIBG1j/qK2l xubPWa7RYlDD2sD9jnKLrBHOqpi+E29OEOYuGfI8XZrjm+XLih /dHjL+52ERSTnIdKWbMBeYdTudzoyYVBPrVZ0M3E0FT0ra+vRn CeHuOA4MCekxWjHeXZ0W12DwNbnovXNGmiu6cbM6XIeSBr5mmO yYWhJjN3yIxz1fLwBceSElPSCCiSC1T8+lDnXTjtexIb/LqHA= = 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370566116 news.xs4all.nl 15913 [2001:888:2000:d::a6]:40154 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47289 On 06/06/2013 08:03 PM, cerr wrote: > Hi, > > I have a process that I can trigger only at a certain time. Assume I have a TDM period of 10min, that means, I can only fire my trigger at the 5th minute of every 10min cycle i.e. at XX:05, XX:15, XX:25... For hat I came up with following algorithm which oly leaves the waiting while loop if minute % TDM/2 is 0 but not if minute % TDM is 0: > min = datetime.datetime.now().timetuple().tm_hour*60 + datetime.datetime.now().timetuple().tm_min > while not (min%tdm_timeslot != 0 ^ min%(int(tdm_timeslot/2)) != 0): You might have spent three minutes and simplified this for us. And in the process discovered the problem. (BTW, min() is a builtin function, so it's not really a good idea to be shadowing it.) You didn't give python version, so my sample is assuming Python 2.7 For your code it shouldn't matter. tdm = 10 tdm2 = 5 y = min(3,4) print y for now in range(10,32): print now, now%tdm, now%tdm2, print not(now % tdm !=0 ^ now%tdm2 !=0) #bad print not((now % tdm !=0) ^ (now%tdm2 !=0)) #good Your problem is one of operator precedence. Notice that ^ has a higher precedence than != operator, so you need the parentheses I added in the following line. What I don't understand is why you used this convoluted approach. Why not print now%tdm != tdm2 For precedence rules, see: http://docs.python.org/2/reference/expressions.html#operator-precedence -- DaveA