Problem with time.time() standing still

Danyel Lawson danyellawson at gmail.com
Sat May 5 16:17:52 EDT 2012


Add a time.sleep(0) call to all your loops. Multithreading in Python
is a cooperative cross platform threading simulation if you have tight
loops Python won't task switch until you make a system call.
Potentially preventing internal library variables from being updated.

Your five minute interval may be almost exactly how long it takes to
process a flooded queue in a tight loop in your program and it may be
why it continues to happen as the queue waits to fill again while
processing happens.

You can simulate the progression of time by overriding the time.time
function by simply setting it to a function that just increments a
module level or function property variable. You can also override the
time.time function to return the posix time function's value to maybe
get around whatever optimization is happening in the time.time
function to pass back the same value.

If you post your sample code that exhibits the same behavior it may be
obvious to someone on the list as to what is the problem.



On Sat, May 5, 2012 at 3:33 PM, Bob Cowdery <bob at bobcowdery.plus.com> wrote:
> Hi all,
>
> I've been a long time user of Python and written many extensions but
> this problem has me stumped.
>
> I've written a straight forward extension that wraps a vendors SDK for a
> video capture card. All works well except that in the Python thread on
> which I call the extension, after certain calls that I believe are using
> DirectShow,  time stands still. The thread returns fine as the extension
> does its stuff in its own threads. In all other respects the Python
> thread seems unaffected but calls to time.time() always return the same
> time which is usually several seconds in the past or future and always
> has no fractional part. If I leave it long enough time will suddently
> jump forward after a few minutes, then again after a few minutes more.
>
> I've never encountered this behaviour before and can't understand what
> on earth is going on. If I call the 'C' time() function just the other
> side of my call to the extension the time is ticking along fine. It's
> just the one Python thread that is affected. If I call from the main
> thread then the main thread is affected. The calling program I've used
> to test this is just a few lines long.
>
> I believe the time function is a thin wrapper over the 'C' runtime so
> its very odd that time only stands still on the Python side but not on
> the 'C' side. As time is built in I've not looked at the code as its not
> in the distribution. Don't know if it would help to do that.
>
> This also can affect the time.sleep() function making it return
> immediately but that only seems to happen in my full application.
>
> Any ideas would be very greatly received.
>
> Bob
> --
> http://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list