This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients brett.cannon, ncoghlan, pitrou
Date 2010-08-22.09:16:13
SpamBayes Score 3.3538565e-06
Marked as misclassified No
Message-id <1282468576.33.0.274928257343.issue9657@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2010-08-22 09:16:16ncoghlansetrecipients: + ncoghlan, brett.cannon, pitrou
2010-08-22 09:16:16ncoghlansetmessageid: <1282468576.33.0.274928257343.issue9657@psf.upfronthosting.co.za>
2010-08-22 09:16:14ncoghlanlinkissue9657 messages
2010-08-22 09:16:13ncoghlancreate