Why does this code crash python?

Mythmon at gmail.com Mythmon at gmail.com
Sat Nov 11 19:48:06 EST 2006



On Nov 11, 3:23 pm, Dennis Lee Bieber <wlfr... at ix.netcom.com> wrote:
> I have no knowledge of Console, but under Windows I was able to hack
> this (see bottom of post) together using only one non-portable library
> -- msvcrt. Oh, and an ActiveState 2.4 build. I'm not touching 2.5 until
> a lot of 3rd party stuff is rebuilt and installers are available.
>

And here I am thinking this was going to be an easy project. I haven't
had a chance to work on this since my last message, but that example
should be a good thing, since now i have an example of how threads
/should/ be done. I was pretty much just guessing so far.

>
> >             newTime = time.time()
> >             timeLeft[turn] -= newTime - oldTime[turn]        I'd duplicated this form, but it is wrong... when the clock swaps it
> will immediately decrement the current clock by the difference since it
> was last updated!
>
> >             if float(seconds[0]) < 10: seconds[0] = '0' +
> > seconds[0][:-1]
> >             if float(seconds[1]) < 10: seconds[1] = '0' +
> > seconds[1][:-1]        I've not handled leading 0s on the seconds field (I tried, but can't
> figure out how to specify zero-filled field width for floats -- works
> for integers)
>

I ran into the same problem, thats why I did it the way I did, instead
of continuing to wrestle with python's string formatting.

> >         go = True
> >         while go:        Why define "go" when it never changes

Whenever I make infinite loops, I put in a control variable so I could
stop it if I want, which I was planning on doing, when the time runs
out or something like that.


>
>         Note that I lock access to timeLeft and side to ensure they don't
> change in the middle of access; may not have been critical, but why risk
> it (and if the code gets expanded so the changes take more time -- or
> multiple look-ups using side).
>
>         getch() doesn't seem to return a value for <ctrl-c>, so I used
> <ctrl-z>
>
>         Uh, it also updates the time with an invalid negative before it
> exits <G>

Now to see if I can get this to work for my self with an example. This
is more a learning project than something that has to be done.




More information about the Python-list mailing list