[Python-Dev] Fwd: [ python-Patches-1744382 ] Read Write lock
Jean-Paul Calderone
exarkun at divmod.com
Fri Jul 6 20:26:23 CEST 2007
On Fri, 6 Jul 2007 10:47:16 -0700, Mike Klaas <mike.klaas at gmail.com> wrote:
>On 6-Jul-07, at 6:45 AM, Yaakov Nemoy wrote:
>
>>
>> I can do the other three parts, but I am wondering, how do I write a
>> deterministic test unit for my patch? How is it done with the
>> threading model in python in general?
>
>I don't know how it is done in general, but for reference, here are
>some of the unittests for my read/write lock class:
>
> [snip]
>
> read.release()
> self.assertEqual(wrlock.readerCount, 0)
> time.sleep(.1)
> self.assertTrue(writer.gotit)
Not exactly deterministic. Instead of a flag attribute, try using an Event or
a Condition. Either of these will let you know exactly when the necessary
operation has completed.
Jean-Paul
More information about the Python-Dev
mailing list