You can join the for and while like this:

```python
while len(self._ongoing_defers) > 0:
    d = self._ongoing_defers.pop()
    d.cancel()
```