Is time.time() < time.time() always true?

1 view
Skip to first unread message

flamesrock

unread,
Nov 21, 2006, 6:10:25 PM11/21/06
to
So, I was blazin' some mad chronix, as they say, and got on to thinking
about Python.

The question was, is the statement:

time.time() < time.time()

always true? Seems it should be false, since the statement itself
occurs at one time instant.. but of course we know that python doesn't
execute code that way.. So my question is, why doesn't Python work this
way?


(PS, I wasn't smoking anything, its a figure of speech :) )

Chris Mellon

unread,
Nov 21, 2006, 6:25:44 PM11/21/06
to pytho...@python.org
On 21 Nov 2006 15:10:25 -0800, flamesrock <flame...@gmail.com> wrote:
> So, I was blazin' some mad chronix, as they say, and got on to thinking
> about Python.
>
> The question was, is the statement:
>
> time.time() < time.time()
>
> always true? Seems it should be false, since the statement itself
> occurs at one time instant.. but of course we know that python doesn't
> execute code that way.. So my question is, why doesn't Python work this
> way?
>

This would only be false if the time between the 2 calls was less than
the precision of the OS call that time.time uses.

Delaney, Timothy (Tim)

unread,
Nov 21, 2006, 6:33:54 PM11/21/06
to pytho...@python.org
Chris Mellon wrote:

So long as the clock on the machine it's running on is not set backwards
between the two calls, you can guarantee that

time.time() <= time.time()

will always evaluate true.

However, it's always possible (though incredibly unlikely) that an
external process changes the clock between the two system calls that are
made.

Tim Delaney

Bjoern Schliessmann

unread,
Nov 21, 2006, 6:40:22 PM11/21/06
to
flamesrock wrote:

> always true? Seems it should be false, since the statement itself
> occurs at one time instant.. but of course we know that python
> doesn't execute code that way..

C++ also wouldn't. How could multiple object instantiations be
atomic?

Regards,


Björn

--
BOFH excuse #42:

spaghetti cable cause packet failure

Gabriel Genellina

unread,
Nov 21, 2006, 7:41:07 PM11/21/06
to flamesrock, pytho...@python.org
At Tuesday 21/11/2006 20:10, flamesrock wrote:

>The question was, is the statement:
>
>time.time() < time.time()
>
>always true? Seems it should be false, since the statement itself
>occurs at one time instant.. but of course we know that python doesn't
>execute code that way.. So my question is, why doesn't Python work this
>way?

The only thing Python can guarantee, is that the left expression is
evaluated before the right one (5.13 Evaluation order, Language Reference).

Then, whether the first call yields a result always less (or equal)
to the second, is out of Python scope (and control).
(They might be equal if both calls get the same quantum of time; they
might be reversed if some other process sets the time in the past).


--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

Ben Finney

unread,
Nov 21, 2006, 8:18:06 PM11/21/06
to pytho...@python.org
"Delaney, Timothy (Tim)" <tdel...@avaya.com> writes:

> So long as the clock on the machine it's running on is not set
> backwards between the two calls, you can guarantee that
>
> time.time() <= time.time()
>
> will always evaluate true.

Really? Where does Python guarantee that the left side *must* be
evaluated before the right side of a comparison? (If the right side
were to be evaluated first, the left might end up with a greater
value.)

--
\ "A free society is one where it is safe to be unpopular." -- |
`\ Adlai Ewing Stevenson |
_o__) |
Ben Finney

Ben Finney

unread,
Nov 21, 2006, 8:31:14 PM11/21/06
to pytho...@python.org
Gabriel Genellina <gags...@yahoo.com.ar> writes:

> The only thing Python can guarantee, is that the left expression is
> evaluated before the right one (5.13 Evaluation order, Language
> Reference).

Thanks, that answers my question asked elsewhere.

--
\ "One thing vampire children have to be taught early on is, |
`\ don't run with a wooden stake." -- Jack Handey |
_o__) |
Ben Finney

Noah Rawlins

unread,
Nov 21, 2006, 8:36:05 PM11/21/06
to
Ben Finney wrote:
> Really? Where does Python guarantee that the left side *must* be
> evaluated before the right side of a comparison? (If the right side
> were to be evaluated first, the left might end up with a greater
> value.)
>

http://docs.python.org/ref/evalorder.html

AndyR

unread,
Nov 21, 2006, 10:26:04 PM11/21/06
to
Hi all:

From my experience with os's.
Time is updated at intervals- they may be as low as 1mS See . So for that
millisecond multiple readings of the time will always return the same
result. Therefore time.time() < time.time() will be false for most readings.

However the result could be true if you catch the exact time when the os
updates its clock. It will only be True for a single execution of the line
and you will have to be lucky to catch it at just the right time.

Of course if you hard loop over the interval its possible to see the
transition.

for x in xrange (10000):
t = time.time()
if t < time.time:
print "transition at ", t

Enjoy.
Andy

"Ben Finney" <bignose+h...@benfinney.id.au> wrote in message
news:mailman.568.11641593...@python.org...

Hendrik van Rooyen

unread,
Nov 22, 2006, 1:56:48 AM11/22/06
to pytho...@python.org
"flamesrock" <flame...@gmail.com> wrote:

8<----------------------------------

> .... since the statement itself


> occurs at one time instant..

nothing, but nothing, can occur at one time instant....

- Hendrik

Fredrik Lundh

unread,
Nov 22, 2006, 2:44:15 AM11/22/06
to pytho...@python.org
Ben Finney wrote:


> Really? Where does Python guarantee that the left side *must* be
> evaluated before the right side of a comparison?

in the language reference:

http://docs.python.org/ref/evalorder.html

</F>

Tim Roberts

unread,
Nov 23, 2006, 4:42:19 PM11/23/06
to

Well, as long as we're being pedantic, surely that should read "only one
thing can occur at any time instant..."
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

Hendrik van Rooyen

unread,
Nov 24, 2006, 1:51:32 AM11/24/06
to Tim Roberts, pytho...@python.org
"Tim Roberts" <ti...@probo.com> wrote:


> "Hendrik van Rooyen" <ma...@microcorp.co.za> wrote:
>
> >"flamesrock" <flame...@gmail.com> wrote:
> >
> >8<----------------------------------
> >
> >> .... since the statement itself
> >> occurs at one time instant..
> >
> >nothing, but nothing, can occur at one time instant....
>
> Well, as long as we're being pedantic, surely that should read "only one
> thing can occur at any time instant..."

No its worse than that - what I mean is that everything takes finite time...

:-) Hendrik


Reply all
Reply to author
Forward
0 new messages