sys.setcheckinterval query

Discussion in 'Python' started by Anand Pillai, Jul 20, 2003.

  1. Anand Pillai

    Anand Pillai Guest

    Quoting from documentation on sys module in python
    standard documentation.

    """
    setcheckinterval(interval)
    Set the interpreter's ``check interval''. This integer value
    determines how often the interpreter checks for periodic things such
    as thread switches and signal handlers. The default is 10, meaning the
    check is performed every 10 Python virtual instructions. Setting it to
    a larger value may increase performance for programs using threads.
    Setting it to a value <= 0 checks every virtual instruction,
    maximizing responsiveness as well as overhead.
    """
    I have a program that uses multiple threads. Is there any direct
    correlation
    between the number of threads my program might spawn and the value of
    ther
    'interval' variable.

    I am interested in the last but one statement which says, "Setting it
    to a larger value may increase performance for programs using
    threads.". So my question is what would that value be? How can I find
    out the number of
    python 'virtual instructions' for every function I have?

    Thanks

    ~Anand
    Anand Pillai, Jul 20, 2003
    #1
    1. Advertising

  2. Anand Pillai

    Peter Hansen Guest

    Anand Pillai wrote:
    >
    > """
    > setcheckinterval(interval)
    > Set the interpreter's ``check interval''. This integer value
    > [...]
    > """
    > I am interested in the last but one statement which says, "Setting it
    > to a larger value may increase performance for programs using
    > threads.". So my question is what would that value be? How can I find
    > out the number of python 'virtual instructions' for every function I have?


    Do you really want to waste time optimizing at such a level? I suspect
    it's very unlikely you will notice any difference other than with
    order-of-magnitude changes. In other words, it's normally every 10
    instructions, but if you change it to 100 or 1000 you could notice a
    difference. (Zope sets the checkinterval to 120 (in the version I checked),
    but I think I'd be surprised if 100 or 140 turned out much different.
    Trying to "tune" it to, say 27, or 73, or something would be sheer insanity.

    If you need better performance than what you are getting, find your
    bottlenecks by profiling and optimize there, or write a C extension,
    or use Pyrex, or Psycho or something.

    (To find the number of bytecode instructions, use module "dis", BTW.)

    -Peter
    Peter Hansen, Jul 21, 2003
    #2
    1. Advertising

  3. Anand Pillai

    Aahz Guest

    In article <>,
    Anand Pillai <> wrote:
    >
    >"""
    >setcheckinterval(interval)
    > Set the interpreter's ``check interval''. This integer value
    >determines how often the interpreter checks for periodic things such
    >as thread switches and signal handlers. The default is 10, meaning the
    >check is performed every 10 Python virtual instructions. Setting it to
    >a larger value may increase performance for programs using threads.
    >Setting it to a value <= 0 checks every virtual instruction,
    >maximizing responsiveness as well as overhead.
    >"""


    Note that Python 2.3 changes the default to 100, so be careful about
    hard-coding anything.
    --
    Aahz () <*> http://www.pythoncraft.com/

    This is Python. We don't care much about theory, except where it intersects
    with useful practice. --Aahz
    Aahz, Jul 23, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ronald Meier
    Replies:
    2
    Views:
    1,481
    Keith S.
    Oct 21, 2003
  2. Roman Neuhauser
    Replies:
    0
    Views:
    653
    Roman Neuhauser
    Apr 4, 2005
  3. Replies:
    2
    Views:
    649
    velle
    Jan 5, 2006
  4. k3xji
    Replies:
    1
    Views:
    296
  5. k3xji
    Replies:
    0
    Views:
    283
    k3xji
    Apr 17, 2009
Loading...

Share This Page