Serhiy Storchaka added the comment:

This is a toy example that exposes the problem, but the problem itself is not a 
toy problem. The key point is that calculating slice indices cause executing 
Python code and releases GIL. In multithread program a sequence can be changed 
not in toy __index__ method, but in other thread, in legitimate code. This is 
very hardly reproducible bug.

Variants B are not efficient. To determine the size of a sequence we should 
call its __len__() method. This is less efficient than using macros Py_SIZE() 
or PyUnicode_GET_LENGTH(). And it is not always possible to pass a sequence. In 
multidimensional array there is no such sequence (see for example 
_testbuffer.ndarray).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue27867>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to