X-Received: by 10.224.174.145 with SMTP id t17mr1622765qaz.4.1370623101967; Fri, 07 Jun 2013 09:38:21 -0700 (PDT) X-Received: by 10.50.127.231 with SMTP id nj7mr489906igb.17.1370623101931; Fri, 07 Jun 2013 09:38:21 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!ch1no3049895qab.0!news-out.google.com!y6ni1135qax.0!nntp.google.com!ch1no3049887qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.python Date: Fri, 7 Jun 2013 09:38:21 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=96.49.68.18; posting-account=ITQB8goAAACqwP7vVe7b-QwIWpcBL1Ll NNTP-Posting-Host: 96.49.68.18 References: <46d8c42f-fdfd-49a5-96e8-ec53d5e599d5@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <2824bb86-2013-4560-a78e-ee4cc7fa4792@googlegroups.com> Subject: Re: trigger at TDM/2 only From: cerr Injection-Date: Fri, 07 Jun 2013 16:38:21 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Xref: csiph.com comp.lang.python:47339 MRAB, Thanks for the hint! Yep, that's much easier! Thanks! :) Ron On Thursday, June 6, 2013 5:49:55 PM UTC-7, MRAB wrote: > On 07/06/2013 01:03, cerr wrote: >=20 > > Hi, >=20 > > >=20 > > I have a process that I can trigger only at a certain time. Assume I ha= ve 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 minu= te % TDM/2 is 0 but not if minute % TDM is 0: >=20 > > min =3D datetime.datetime.now().timetuple().tm_hour*60 + datetime.date= time.now().timetuple().tm_min >=20 > > while not (min%tdm_timeslot !=3D 0 ^ min%(int(tdm_timeslot/2)) !=3D 0)= : >=20 > > time.sleep(10) >=20 > > logger.debug("WAIT "+str(datetime.datetime.now().timetuple().tm_hour*= 60 + datetime.datetime.now().timetuple().tm_min)) >=20 > > logger.debug(str(min%(int(tdm_timeslot/2)))+" - "+str(min%tdm_timeslo= t)) >=20 > > min =3D datetime.datetime.now().timetuple().tm_hour*60 + datetime.dat= etime.now().timetuple().tm_min >=20 > > logger.debug("RUN UPDATE CHECK...") >=20 > > >=20 > > But weird enough, the output I get is something like this: >=20 > > I would expect my while to exit the loop as soon as the minute turns 14= 35... why is it staying in? What am I doing wrong here? >=20 > > >=20 > > WAIT 1434 >=20 > > 3 - 3 >=20 > > WAIT 1434 >=20 > > 4 - 4 >=20 > > WAIT 1434 >=20 > > 4 - 4 >=20 > > WAIT 1434 >=20 > > 4 - 4 >=20 > > WAIT 1434 >=20 > > 4 - 4 >=20 > > WAIT 1434 >=20 > > 4 - 4 >=20 > > WAIT 1435 >=20 > > 4 - 4 >=20 > > WAIT 1435 >=20 > > 0 - 5 >=20 > > WAIT 1435 >=20 > > 0 - 5 >=20 > > WAIT 1435 >=20 > > 0 - 5 >=20 > > WAIT 1435 >=20 > > 0 - 5 >=20 > > WAIT 1435 >=20 > > 0 - 5 >=20 > > WAIT 1436 >=20 > > 0 - 5 >=20 > > RUN UPDATE CHECK... >=20 > > >=20 > Possibly it's due to operator precedence. The bitwise operators &, | >=20 > and ^ have a higher precedence than comparisons such as !=3D. >=20 >=20 >=20 > A better condition might be: >=20 >=20 >=20 > min % tdm_timeslot !=3D tdm_timeslot // 2 >=20 >=20 >=20 > or, better yet, work out how long before the next trigger time and then >=20 > sleep until then.