In article <[EMAIL PROTECTED]>, Carl J. Van Arsdall <[EMAIL PROTECTED]> wrote: > >I have some questions regarding python's threading.
These answers assume you're using CPython; Jython and IronPython have different answers. >1. Who schedules which threads run and when? Is this something left up >to the operating system or does python provide a mechanism for this? Strictly OS -- Python provides no control. >2. I've read that python threads don't like to allow other threads to >run except in certain situations, these would be situations where there >is sleep or I/O happening, is this true? If so, what are the cases in >which a python thread would not give up the processor? There is only a single thread of Python code running at any time. Calling out to external libraries (e.g. C code) can release the Global Interpreter Lock. Python's standard I/O routines do this automatically for you, but you're free to write your own code that does this (e.g. mxODBC). >3. Is there a way to which thread is running? I mean something a bit >more robust than a print statement inside the thread, I want to be able >to see when a context switch occurs, is this possible? The reason for >this is I will have threads deadlocked waiting for I/O and I am >interested to see how often context switching occurs. You'd have to write some kind of logging. You can use the logging module. -- Aahz ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ "Don't listen to schmucks on USENET when making legal decisions. Hire yourself a competent schmuck." --USENET schmuck (aka Robert Kern) -- http://mail.python.org/mailman/listinfo/python-list