[issue30011] HTMLParser class is not thread safe
Serhiy Storchaka
report at bugs.python.org
Sat Apr 15 02:12:21 EDT 2017
Serhiy Storchaka added the comment:
There is nothing wrong with building entitydefs multiple times since the result is same. An alternative is using locking, but this is more cumbersome solution. And building entitydefs is much faster than importing the threading module.
$ ./python -m timeit -s 'from HTMLParser import HTMLParser; p = HTMLParser()' -- 'HTMLParser.entitydefs = None; p.unescape("&")'
1000 loops, best of 3: 412 usec per loop
$ ./python -m timeit -s 'import sys; m = sys.modules.copy()' -- 'import threading; sys.modules.clear(); sys.modules.update(m)'
100 loops, best of 3: 5.43 msec per loop
Current solution is faster in single-thread case, correct likely fast enough in multi-thread case.
----------
nosy: +serhiy.storchaka
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30011>
_______________________________________
More information about the Python-bugs-list
mailing list