Simple threading

Gabriel Genellina gagsl-py at yahoo.com.ar
Sat Nov 25 00:56:47 EST 2006


At Thursday 23/11/2006 12:28, jrpfinch wrote:

>I'm just getting started on threading and was wondering why the
>following code does not work (i know globals is bad style - I'll
>eliminate them eventually).  All I get is a blank cursor flashing.

You've got your example already working.
Globals are bad style, but worse, threads and globals don't mix very 
well: you need some sort of syncronization for accessing globals 
(specially for writing them).

>class ImapThread(threading.Thread):
>     def run(self):
>         global g_currenttick
>         if time.time() > (g_datum + (g_secondspertick *
>g_currenttick)):
>             print "Ticked %s" % g_currenttick
>             g_currenttick=g_currenttick+1
>             print g_currenttick

Having more than one thread, g_currenttick could have been modified 
*after* you read its value and *before* you write it back, so you 
lose the count.


-- 
Gabriel Genellina
Softlab SRL 

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar



More information about the Python-list mailing list