Simple threading

jrpfinch jrpfinch at gmail.com
Thu Nov 23 10:28:17 EST 2006


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.

Many thanks

Jon

import threading
import sys
import time
global g_datum
global g_rawfile
global g_rawtext
global g_overs
global g_currentover
global g_secondspertick


g_secondspertick=5
g_datum=time.time()
g_currenttick=1
g_rawfile=open('inputashes.txt','r')
g_rawtext=g_rawfile.read()
g_overs=g_rawtext.split('<P>')
g_currentover=0


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
            sys.stdout.flush()
    time.sleep(0.01)

def main():
    ImapThread().start()
    while 1:
        pass

if __name__ == "__main__":
    main()




More information about the Python-list mailing list