Simple Threading Example Doesn't Work (2.5.1)

S

Seun Osewa

Hello,

I've tried to run several threading examples in Python 2.5.1 (with
Stackless) For example:

import threading

theVar = 1

class MyThread ( threading.Thread ):

def run ( self ):

global theVar
print 'This is thread ' + str ( theVar ) + ' speaking.'
print 'Hello and good bye.'
theVar = theVar + 1

for x in xrange ( 20 ):
MyThread().start()

It doesn't work. It says there's an error in Queue.py in:
self.mutex=threading.Lock()
AttributeError: 'module' object has no attribute Lock

The funny thing is that when I use the -O switch, it seems to work.
I'm baffled by this. What do you think is happening?

Thanks.
 
M

Marc 'BlackJack' Rintsch

Seun Osewa said:
I've tried to run several threading examples in Python 2.5.1 (with
Stackless) For example:

import threading

theVar = 1

class MyThread ( threading.Thread ):

def run ( self ):

global theVar
print 'This is thread ' + str ( theVar ) + ' speaking.'
print 'Hello and good bye.'
theVar = theVar + 1

for x in xrange ( 20 ):
MyThread().start()

It doesn't work. It says there's an error in Queue.py in:
self.mutex=threading.Lock()
AttributeError: 'module' object has no attribute Lock

The funny thing is that when I use the -O switch, it seems to work.
I'm baffled by this. What do you think is happening?

Any chance that you have a module called `threading` that is not the one
in the standard library? Perhaps you named the script above `threading.py`!?

Ciao,
Marc 'BlackJack' Rintsch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top