Fail if the given callable produces any reference cycles. If called with all arguments omitted, may be used as a context manager:: with assert_no_gc_cycles(): do_something() Parameters ---------- func : callable The callable to test. \\*args :
(*args, **kwargs)
| 2630 | |
| 2631 | |
| 2632 | def assert_no_gc_cycles(*args, **kwargs): |
| 2633 | """ |
| 2634 | Fail if the given callable produces any reference cycles. |
| 2635 | |
| 2636 | If called with all arguments omitted, may be used as a context manager:: |
| 2637 | |
| 2638 | with assert_no_gc_cycles(): |
| 2639 | do_something() |
| 2640 | |
| 2641 | Parameters |
| 2642 | ---------- |
| 2643 | func : callable |
| 2644 | The callable to test. |
| 2645 | \\*args : Arguments |
| 2646 | Arguments passed to `func`. |
| 2647 | \\*\\*kwargs : Kwargs |
| 2648 | Keyword arguments passed to `func`. |
| 2649 | |
| 2650 | Returns |
| 2651 | ------- |
| 2652 | Nothing. The result is deliberately discarded to ensure that all cycles |
| 2653 | are found. |
| 2654 | |
| 2655 | """ |
| 2656 | if not args: |
| 2657 | return _assert_no_gc_cycles_context() |
| 2658 | |
| 2659 | func = args[0] |
| 2660 | args = args[1:] |
| 2661 | with _assert_no_gc_cycles_context(name=func.__name__): |
| 2662 | func(*args, **kwargs) |
| 2663 | |
| 2664 | |
| 2665 | def break_cycles(): |
searching dependent graphs…