On Mar 11, 4:15 pm, Oltmans <rolf.oltm...@gmail.com> wrote: > Hi, all. I'm trying to use Mechanize in a multithreaded program-- > purpose of which is to fill out a form on a website using concurrent > threads. Guys, trust me I've spent a lot of time to figure out the > problem but I'm completed puzzled. Firstly, I've listed the errors and > then the program listing (with imports omitted) > > Error: > > Traceback (most recent call last): > File "C:\Python25\lib\threading.py", line 460, in __bootstrap > self.run() > File "tmechanize.py", line 21, in run > with lock: > NameError: global name 'lock' is not defined
Time for the obvious question - where do you define "lock"? If you're trying to put a mutex around your increment, you need a lock pre- defined to use it. So, you'll need to add something like "lock = Lock ()" near the top, with a "global lock" before you try using it in your with statement. If you try using Lock() directly in the thread, you'll create a new lock per thread, thus defeating the purpose of trying to lock in the first place. ~G -- http://mail.python.org/mailman/listinfo/python-list