|
3 | 3 | import glob
|
4 | 4 | import os
|
5 | 5 | import re
|
| 6 | +import threading |
6 | 7 | import warnings
|
7 | 8 |
|
| 9 | + |
| 10 | +# imports needed for Python 3.x but will fail under Python 2.x |
8 | 11 | try:
|
9 |
| - from importlib import import_module |
| 12 | + from importlib import import_module, reload |
10 | 13 | except ImportError:
|
11 | 14 | import_module = __import__
|
12 | 15 |
|
| 16 | + |
13 | 17 | from distutils.version import LooseVersion
|
14 | 18 |
|
15 | 19 | import pytest
|
|
22 | 26 | from pandas.compat import (map, zip, StringIO, string_types, BytesIO,
|
23 | 27 | is_platform_windows, PY3)
|
24 | 28 | from pandas.io.common import URLError, urlopen, file_path_to_url
|
| 29 | +import pandas.io.html |
25 | 30 | from pandas.io.html import read_html
|
26 | 31 | from pandas._libs.parsers import ParserError
|
27 | 32 |
|
@@ -931,3 +936,31 @@ def test_same_ordering():
|
931 | 936 | dfs_lxml = read_html(filename, index_col=0, flavor=['lxml'])
|
932 | 937 | dfs_bs4 = read_html(filename, index_col=0, flavor=['bs4'])
|
933 | 938 | assert_framelist_equal(dfs_lxml, dfs_bs4)
|
| 939 | + |
| 940 | + |
| 941 | +class ErrorThread(threading.Thread): |
| 942 | + def run(self): |
| 943 | + try: |
| 944 | + super(ErrorThread, self).run() |
| 945 | + except Exception as e: |
| 946 | + self.err = e |
| 947 | + else: |
| 948 | + self.err = None |
| 949 | + |
| 950 | + |
| 951 | +@pytest.mark.slow |
| 952 | +def test_importcheck_thread_safety(): |
| 953 | + |
| 954 | + # force import check by reinitalising global vars in html.py |
| 955 | + reload(pandas.io.html) |
| 956 | + |
| 957 | + filename = os.path.join(DATA_PATH, 'valid_markup.html') |
| 958 | + helper_thread1 = ErrorThread(target=read_html, args=(filename,)) |
| 959 | + helper_thread2 = ErrorThread(target=read_html, args=(filename,)) |
| 960 | + |
| 961 | + helper_thread1.start() |
| 962 | + helper_thread2.start() |
| 963 | + |
| 964 | + while(helper_thread1.is_alive() or helper_thread2.is_alive()): |
| 965 | + pass |
| 966 | + assert None is helper_thread1.err is helper_thread2.err |
0 commit comments