Back to index

python3.2  3.2.2
Classes | Functions | Variables
test.test_threaded_import Namespace Reference

Classes

class  Finder
class  FlushingFinder
class  ThreadedImportTests

Functions

def task
def test_main

Variables

tuple thread = import_module('_thread')
tuple threading = import_module('threading')
dictionary circular_imports_modules

Function Documentation

def test.test_threaded_import.task (   N,
  done,
  done_tasks,
  errors 
)

Definition at line 18 of file test_threaded_import.py.

00018 
00019 def task(N, done, done_tasks, errors):
00020     try:
00021         # We don't use modulefinder but still import it in order to stress
00022         # importing of different modules from several threads.
00023         if len(done_tasks) % 2:
00024             import modulefinder
00025             import random
00026         else:
00027             import random
00028             import modulefinder
00029         # This will fail if random is not completely initialized
00030         x = random.randrange(1, 3)
00031     except Exception as e:
00032         errors.append(e.with_traceback(None))
00033     finally:
00034         done_tasks.append(thread.get_ident())
00035         finished = len(done_tasks) == N
00036         if finished:
00037             done.set()
00038 
00039 # Create a circular import structure: A -> C -> B -> D -> A
00040 # NOTE: `time` is already loaded and therefore doesn't threaten to deadlock.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 206 of file test_threaded_import.py.

00206 
00207 def test_main():
00208     run_unittest(ThreadedImportTests)

Here is the call graph for this function:


Variable Documentation

Initial value:
00001 {
00002     'A': """if 1:        import time        time.sleep(%(delay)s)        x = 'a'        import C        """,
00003     'B': """if 1:        import time        time.sleep(%(delay)s)        x = 'b'        import D        """,
00004     'C': """import B""",
00005     'D': """import A""",
00006 }

Definition at line 41 of file test_threaded_import.py.

tuple test.test_threaded_import.thread = import_module('_thread')

Definition at line 15 of file test_threaded_import.py.

Definition at line 16 of file test_threaded_import.py.