Skip to content

Commit

Permalink
added test for read_html() thread safety(pandas-dev#16928)
Browse files Browse the repository at this point in the history
  • Loading branch information
3553x committed Jul 16, 2017
1 parent 6000c5b commit 2ca0e18
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pandas/tests/io/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
import glob
import os
import re
import threading
import warnings

try:
from importlib import import_module
except ImportError:
import_module = __import__

try:
from importlib import reload
except ImportError:
pass

from distutils.version import LooseVersion

import pytest
Expand All @@ -22,6 +28,7 @@
from pandas.compat import (map, zip, StringIO, string_types, BytesIO,
is_platform_windows, PY3)
from pandas.io.common import URLError, urlopen, file_path_to_url
import pandas.io.html
from pandas.io.html import read_html
from pandas._libs.parsers import ParserError

Expand Down Expand Up @@ -931,3 +938,24 @@ def test_same_ordering():
dfs_lxml = read_html(filename, index_col=0, flavor=['lxml'])
dfs_bs4 = read_html(filename, index_col=0, flavor=['bs4'])
assert_framelist_equal(dfs_lxml, dfs_bs4)

class ErrorThread(threading.Thread):
def run(self):
try:
super(ErrorThread, self).run()
except Exception as e:
self.err = e
else:
self.err = None

@pytest.mark.slow
def test_importcheck_thread_safety():
reload(pandas.io.html)
filename = os.path.join(DATA_PATH, 'valid_markup.html')
helper_thread1 = ErrorThread(target = read_html, args = (filename,))
helper_thread2 = ErrorThread(target = read_html, args = (filename,))
helper_thread1.start()
helper_thread2.start()
while(helper_thread1.is_alive() or helper_thread2.is_alive()):
pass
assert None == helper_thread1.err == helper_thread2.err

0 comments on commit 2ca0e18

Please sign in to comment.