Skip to content

Commit 2fdcfb1

Browse files
committed
BUG: Improved thread safety for read_html() GH16928
1 parent 7ffe7fc commit 2fdcfb1

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

doc/source/whatsnew/v0.21.0.txt

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ I/O
164164

165165
- Bug in :func:`read_stata` where value labels could not be read when using an iterator (:issue:`16923`)
166166

167+
- Bug in :func:`read_html` importcheck fails when run concurrently (:issue:`16928`)
168+
167169
Plotting
168170
^^^^^^^^
169171
- Bug in plotting methods using ``secondary_y`` and ``fontsize`` not setting secondary axis font size (:issue:`12565`)

pandas/io/html.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ def _importers():
3737
if _IMPORTS:
3838
return
3939

40-
_IMPORTS = True
41-
4240
global _HAS_BS4, _HAS_LXML, _HAS_HTML5LIB
4341

4442
try:
@@ -59,6 +57,8 @@ def _importers():
5957
except ImportError:
6058
pass
6159

60+
_IMPORTS = True
61+
6262

6363
#############
6464
# READ HTML #

pandas/tests/io/test_html.py

+23
Original file line numberDiff line numberDiff line change
@@ -931,3 +931,26 @@ def test_same_ordering():
931931
dfs_lxml = read_html(filename, index_col=0, flavor=['lxml'])
932932
dfs_bs4 = read_html(filename, index_col=0, flavor=['bs4'])
933933
assert_framelist_equal(dfs_lxml, dfs_bs4)
934+
935+
936+
class ErrorThread(threading.Thread):
937+
def run(self):
938+
try:
939+
super(ErrorThread, self).run()
940+
except Exception as e:
941+
self.err = e
942+
else:
943+
self.err = None
944+
945+
946+
@pytest.mark.slow
947+
def test_importcheck_thread_safety():
948+
reload(pandas.io.html)
949+
filename = os.path.join(DATA_PATH, 'valid_markup.html')
950+
helper_thread1 = ErrorThread(target=read_html, args=(filename,))
951+
helper_thread2 = ErrorThread(target=read_html, args=(filename,))
952+
helper_thread1.start()
953+
helper_thread2.start()
954+
while(helper_thread1.is_alive() or helper_thread2.is_alive()):
955+
pass
956+
assert None is helper_thread1.err is helper_thread2.err

0 commit comments

Comments
 (0)