Nick Coghlan <ncogh...@gmail.com> added the comment:

It would be good if the test timed out rather than deadlocking in the face of a 
broken import lock.

I suggest:
1. Make the two test threads daemon threads
2. Specify a timeout to the join() calls
3. Use self.assertFalse(t1.is_alive()) and self.assertFalse(t2.is_alive()) to 
check the calls actually finished

For your #9260 testing, this looks like it may be a little probabilistic. I 
think you can make the deadlock a near certainty by defining your test modules 
and threads as follows:

# Create a circular import structure: A -> C -> B -> D -> A
circular_imports_modules = {
    'A': """if 1:
        import ev
        ev.evA.wait()
        import time
        time.sleep(%(delay)s)
        x = 'a'
        import C
        """,
    'B': """if 1:
        import ev
        ev.evB.wait()
        import time
        time.sleep(%(delay)s)
        x = 'b'
        import D
        """,
    'C': """import B""",
    'D': """import A""",
    'ev': """if 1:
         import threading;
         evA = threading.Event()
         evB = threading.Event()
         """,
}

        def import_ab():
            import ev
            ev.evB.set()
            import A
            results.append(getattr(A, 'x', None))
        def import_ba():
            import ev
            ev.evA.set()
            import B
            results.append(getattr(B, 'x', None))


(I've done a trick along these lines before, and the above doesn't look quite 
right. Maybe the details will come back to me if I sit on it for a while)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue9657>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to