Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #47288

Re: trigger at TDM/2 only

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'algorithm': 0.04; 'output': 0.05; 'exit': 0.09; 'here?': 0.09; 'means,': 0.09; 'assume': 0.14; '0):': 0.16; 'be:': 0.16; 'bitwise': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'precedence': 0.16; 'precedence.': 0.16; 'weird': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'possibly': 0.26; 'this:': 0.26; 'subject:/': 0.26; 'certain': 0.27; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'then.': 0.30; 'operators': 0.31; 'staying': 0.31; 'run': 0.32; 'period': 0.33; 'something': 0.35; 'but': 0.35; 'i.e.': 0.36; 'skip:" 50': 0.36; 'doing': 0.36; 'next': 0.36; 'hi,': 0.36; 'wrong': 0.37; 'hat': 0.38; 'to:addr:python-list': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; '5th': 0.60; 'such': 0.63; 'soon': 0.63; 'fire': 0.65; 'due': 0.66; 'header:Reply- To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'min': 0.84; 'reply-to:addr:python.org': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=KrN0hwmN c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=oyR3mlnJdzkA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=nY_MpIYKd1QA:10 a=07hAi6Iy7VVHfiq7yR0A:9 a=wPNLvfGTeEIA:10
X-AUTH mrabarnett:2500
Date Fri, 07 Jun 2013 01:49:55 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130509 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-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2832.1370566146.3114.python-list@python.org> (permalink)
Lines 52
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1370566146 news.xs4all.nl 15934 [2001:888:2000:d::a6]:40483
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:47288

Show key headers only | View raw


On 07/06/2013 01:03, 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):
> 		time.sleep(10)
> 		logger.debug("WAIT "+str(datetime.datetime.now().timetuple().tm_hour*60 + datetime.datetime.now().timetuple().tm_min))
> 		logger.debug(str(min%(int(tdm_timeslot/2)))+" - "+str(min%tdm_timeslot))
> 		min = datetime.datetime.now().timetuple().tm_hour*60 + datetime.datetime.now().timetuple().tm_min
> 	logger.debug("RUN UPDATE CHECK...")
>
> But weird enough, the output I get is something like this:
> I would expect my while to exit the loop as soon as the minute turns 1435... why is it staying in? What am I doing wrong here?
>
> WAIT 1434
> 3 - 3
> WAIT 1434
> 4 - 4
> WAIT 1434
> 4 - 4
> WAIT 1434
> 4 - 4
> WAIT 1434
> 4 - 4
> WAIT 1434
> 4 - 4
> WAIT 1435
> 4 - 4
> WAIT 1435
> 0 - 5
> WAIT 1435
> 0 - 5
> WAIT 1435
> 0 - 5
> WAIT 1435
> 0 - 5
> WAIT 1435
> 0 - 5
> WAIT 1436
> 0 - 5
> RUN UPDATE CHECK...
>
Possibly it's due to operator precedence. The bitwise operators &, |
and ^ have a higher precedence than comparisons such as !=.

A better condition might be:

     min % tdm_timeslot != tdm_timeslot // 2

or, better yet, work out how long before the next trigger time and then
sleep until then.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

trigger at TDM/2 only cerr <ron.eggler@gmail.com> - 2013-06-06 17:03 -0700
  Re: trigger at TDM/2 only MRAB <python@mrabarnett.plus.com> - 2013-06-07 01:49 +0100
    Re: trigger at TDM/2 only cerr <ron.eggler@gmail.com> - 2013-06-07 09:38 -0700
  Re: trigger at TDM/2 only Dave Angel <davea@davea.name> - 2013-06-06 20:43 -0400
    Re: trigger at TDM/2 only cerr <ron.eggler@gmail.com> - 2013-06-07 09:35 -0700

csiph-web