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() .. versionadded:: 1.15.0 Parameters ---------- func : callable The cal
(*args, **kwargs)
| 2332 | |
| 2333 | |
| 2334 | def assert_no_gc_cycles(*args, **kwargs): |
| 2335 | """ |
| 2336 | Fail if the given callable produces any reference cycles. |
| 2337 | |
| 2338 | If called with all arguments omitted, may be used as a context manager: |
| 2339 | |
| 2340 | with assert_no_gc_cycles(): |
| 2341 | do_something() |
| 2342 | |
| 2343 | .. versionadded:: 1.15.0 |
| 2344 | |
| 2345 | Parameters |
| 2346 | ---------- |
| 2347 | func : callable |
| 2348 | The callable to test. |
| 2349 | \\*args : Arguments |
| 2350 | Arguments passed to `func`. |
| 2351 | \\*\\*kwargs : Kwargs |
| 2352 | Keyword arguments passed to `func`. |
| 2353 | |
| 2354 | Returns |
| 2355 | ------- |
| 2356 | Nothing. The result is deliberately discarded to ensure that all cycles |
| 2357 | are found. |
| 2358 | |
| 2359 | """ |
| 2360 | if not args: |
| 2361 | return _assert_no_gc_cycles_context() |
| 2362 | |
| 2363 | func = args[0] |
| 2364 | args = args[1:] |
| 2365 | with _assert_no_gc_cycles_context(name=func.__name__): |
| 2366 | func(*args, **kwargs) |
| 2367 | |
| 2368 | |
| 2369 | def break_cycles(): |