[TIP] How do you unit test threading classes?
Laurens Van Houtven
_ at lvh.cc
Fri Jun 6 04:12:58 PDT 2014
Hi Javier
On 06 Jun 2014, at 12:22, Javier Domingo Cansino <javier.domingo at fon.com> wrote:
> I do use locks, and the GIL does somehow make sure that nothing will
> happen between lines (unless you are doing several things on each
> line).
While this is technically true, you don’t have to try particularly hard to "do several things on one line". Calling a method on an object? Two opcodes, probably three (to get the object on the stack in the first place):
In [2]: def f(x):
...: return x.bit_length()
...:
In [3]: dis(f)
2 0 LOAD_FAST 0 (x)
3 LOAD_ATTR 0 (bit_length)
6 CALL_FUNCTION 0 (0 positional, 0 keyword pair)
9 RETURN_VALUE
> The idea would be to have an utility like the following:
>
> while obj.function_being_checked:
> do_thread_safety_checks()
>
> It could maybe iterate between unlocks of the GIL…
I don’t know of anything like this in Python. The automated safety checkers I do know of wouldn’t really work either.
hth
lvh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20140606/2fde3a83/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20140606/2fde3a83/attachment.pgp>
More information about the testing-in-python
mailing list