threaded urllib.urlretrieve() confusion

Martin v. Loewis martin at v.loewis.de
Thu May 9 13:59:11 EDT 2002


Michael Mell <mike at nthwave.net> writes:

> How do I get each doRequest() to begin its process as soon as I call
>     thread.start_new_thread (doRequest, (idStr, ))

That depends on your operating system's scheduling policy, and
somewhat on the Python version. With Python 2.2, on pthread systems
that have PTHREAD_SCOPE_SYSTEM, this attribute is enabled, requesting
from the system that it immediately starts scheduling new threads, and
that they content for the processor with all other processes.

Whether the OS does so is still the system's choice. If you want to
ask the system more strongly to schedule your threads, you can add a
time.sleep call after creating a thread (say, for 0.1 seconds); this
should cause the system to switch threads.

Whether the system switches to your thread is still the system's
choice.  If you absolutely need the thread to start execution, you
need to add a Condition. Make the creating thread wait on the
condition, and make the new thread notify the condition. Then you can
be sure that the new thread has started.

Whether the system continues to run your thread after it notified the
condition is still the system's choice. If you need specific order of
execution, don't use threads.

HTH,
Martin



More information about the Python-list mailing list