<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi Javier<div><br></div><div><div><div><br></div>On 06 Jun 2014, at 12:22, Javier Domingo Cansino &lt;<a href="mailto:javier.domingo@fon.com">javier.domingo@fon.com</a>&gt; wrote:<br><br><blockquote type="cite">I do use locks, and the GIL does somehow make sure that nothing will<br>happen between lines (unless you are doing several things on each<br>line).</blockquote><div><br></div><div>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):</div><div><br></div><div><font face="Monaco">In [2]: def f(x):<br>&nbsp; &nbsp;...: &nbsp; &nbsp; return x.bit_length()<br>&nbsp; &nbsp;...:<br><br>In [3]: dis(f)<br>&nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 LOAD_FAST &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 (x)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3 LOAD_ATTR &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 (bit_length)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 6 CALL_FUNCTION &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 (0 positional, 0 keyword pair)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 9 RETURN_VALUE</font></div><br><blockquote type="cite">The idea would be to have an utility like the following:<br><br>while obj.function_being_checked:<br>&nbsp; &nbsp;do_thread_safety_checks()<br><br>It could maybe iterate between unlocks of the GIL…</blockquote><br></div></div><div>I don’t know of anything like this in Python. The automated safety checkers I do know of wouldn’t really work either.</div><div><br></div><div>hth</div><div>lvh</div></body></html>