How to prevent this from happening?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • phil_nospam_schmidt@yahoo.com

    #1

    How to prevent this from happening?

    Regarding this expression: 1 << x

    I had a bug in my code that made x become Very Large - much larger than
    I had intended. This caused Python, and my PC, to lock up tight as a
    drum, and it appeared that the Python task (Windows XP) was happily and
    rapidly consuming all available virtual memory.

    Presumably, Python was trying to create a really really long integer,
    just as I had asked it.

    Is there a way to put a limit on Python, much like there is a stack
    limit, so that this sort of thing can't get out of hand?

  • John Machin

    #2
    Re: How to prevent this from happening?

    On 1/05/2006 12:55 PM, phil_nospam_sch midt@yahoo.com wrote:[color=blue]
    > Regarding this expression: 1 << x
    >
    > I had a bug in my code that made x become Very Large - much larger than
    > I had intended. This caused Python, and my PC, to lock up tight as a
    > drum, and it appeared that the Python task (Windows XP) was happily and
    > rapidly consuming all available virtual memory.
    >
    > Presumably, Python was trying to create a really really long integer,
    > just as I had asked it.
    >
    > Is there a way to put a limit on Python, much like there is a stack
    > limit, so that this sort of thing can't get out of hand?
    >[/color]

    If you mean a command line argument to specify an upper limit for the
    RHS of a << operator, no there isn't one, and no there shouldn't be one.

    To cater for sillinesses that aren't caught by exceptions (or where it
    may be a very long time before the exception is triggered, as in your
    case), I'd suggest placing tests close to the action. For example, if
    you are doing some bit-bashing, "assert nshift <= wordsize" or something
    like that may be appropriate.




    Comment

    • Serge Orlov

      #3
      Re: How to prevent this from happening?

      phil_nospam_sch midt@yahoo.com wrote:[color=blue]
      > Regarding this expression: 1 << x
      >
      > I had a bug in my code that made x become Very Large - much larger than
      > I had intended. This caused Python, and my PC, to lock up tight as a
      > drum, and it appeared that the Python task (Windows XP) was happily and
      > rapidly consuming all available virtual memory.
      >
      > Presumably, Python was trying to create a really really long integer,
      > just as I had asked it.
      >
      > Is there a way to put a limit on Python, much like there is a stack
      > limit, so that this sort of thing can't get out of hand?[/color]

      This is a general problem regardless of programming language and it's
      better solved by OS. Windows has API for limiting resource usage but it
      lacks user tools. At least I'm not aware of them, maybe *you* can find
      them. There is Windows System Resource Manager
      http://www.microsoft.com/technet/dow...srvr/wsrm.mspx It won't
      run on Windows XP, but you may take a look at its distribution CD
      image. If you're lucky maybe there is a command line tool for Windows
      XP.

      Alternatively you can switch to a better OS ;) Any Unix-like (Max OS X,
      Linux, *BSD, etc...), they all have resource usage limiting tools out
      of the box.

      Comment

      Working...