diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-07-06 08:38:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-06 08:38:24 +0300 |
commit | 03b0e8374b2ea93adf8fb6a48db2916f3b0388cc (patch) | |
tree | 12743d6b43e1dff7f8bbacab2b6a5f0bb5a72141 /Lib/test | |
parent | aaa4f991518611d101fba1ef3ecb18d7b385ad5b (diff) | |
download | cpython-git-03b0e8374b2ea93adf8fb6a48db2916f3b0388cc.tar.gz |
[3.6] bpo-30814: Fixed a race condition when import a submodule from a package. (GH-2580). (#2598)
(cherry picked from commit b4baacee1adc06edbe30ac7574d17a8cd168e2e0)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_import/__init__.py | 28 | ||||
-rw-r--r-- | Lib/test/test_import/data/package/__init__.py | 2 | ||||
-rw-r--r-- | Lib/test/test_import/data/package/submodule.py | 0 |
3 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 4aca9e597c..3291d0896c 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -10,6 +10,8 @@ import py_compile import random import stat import sys +import threading +import time import unittest import unittest.mock as mock import textwrap @@ -350,6 +352,32 @@ class ImportTests(unittest.TestCase): with self.assertRaises(ImportError): from test_from_import_AttributeError import does_not_exist + def test_concurrency(self): + sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'data')) + try: + exc = None + def run(): + event.wait() + try: + import package + except BaseException as e: + nonlocal exc + exc = e + + for i in range(10): + event = threading.Event() + threads = [threading.Thread(target=run) for x in range(2)] + try: + with test.support.start_threads(threads, event.set): + time.sleep(0) + finally: + sys.modules.pop('package', None) + sys.modules.pop('package.submodule', None) + if exc is not None: + raise exc + finally: + del sys.path[0] + @skip_if_dont_write_bytecode class FilePermissionTests(unittest.TestCase): diff --git a/Lib/test/test_import/data/package/__init__.py b/Lib/test/test_import/data/package/__init__.py new file mode 100644 index 0000000000..a4f2bc3400 --- /dev/null +++ b/Lib/test/test_import/data/package/__init__.py @@ -0,0 +1,2 @@ +import package.submodule +package.submodule diff --git a/Lib/test/test_import/data/package/submodule.py b/Lib/test/test_import/data/package/submodule.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/Lib/test/test_import/data/package/submodule.py |