Threaded alternatives to smtplib?
Diez B. Roggisch
deets at nospam.web.de
Mon May 4 06:52:05 EDT 2009
Alex Jurkiewicz wrote:
> Gabriel Genellina wrote:
>> Try logging the start/stop of your threads. It may be that your
>> threads stop before you think. The above code works correctly only if
>> you fill the queue before starting any thread - because as soon as a
>> thread sees the queue empty, it finishes.
>> You could use the sample code in the Queue documentation at the end of
> The queue is actually filled before the threads are started, data is
> only removed after they start.
> Logging thread state (at least in debug mode) would be good though. How
> would I go about it in this example? The docs suggest using thread.name,
> but in my current setup I don't have any idea which thread is running.
> Something like this:
> for i in range(CONCURRENCY):
> THREADS.append( threading.Thread(target=threadProcessRecipient,
> args=i, name=i) )
> def threadProcessRecipient(name):
> print "Name is %s" % name
Each thread gets an unique name assigned anyway. Alternatively, you can use
partial to bind parameters to functions. And last but not least to subclass
Thread is also an option.
More information about the Python-list