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.

classification
Title: asyncio cause infinite loop during debug
Type: crash Stage: resolved
Components: asyncio Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Normalize asyncio future and task repr()
View: 47039
Assigned To: Nosy List: asvetlov, kumaraditya, sobolevn, yselivanov, zillionare
Priority: normal Keywords:

Created on 2022-01-02 03:36 by zillionare, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (6)
msg409487 - (view) Author: aaron (zillionare) Date: 2022-01-02 03:36
When running code in debug mode, asyncio sometimes enter into infinite loop, shows as the following:

```
Current thread 0x00007f1c15fc5180 (most recent call first):
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/events.py", line 58 in __repr__
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 139 in repr_instance
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 62 in repr1
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 52 in repr
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 40 in <genexpr>
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 40 in _format_args_and_kwargs
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 56 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 47 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 23 in _format_callback_source
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 32 in format_cb
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 37 in _format_callbacks
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 76 in _future_repr_info
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 139 in repr_instance
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 62 in repr1
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 52 in repr
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 38 in <genexpr>
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 38 in _format_args_and_kwargs
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 56 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 23 in _format_callback_source
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/events.py", line 51 in _repr_info
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/events.py", line 61 in __repr__
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 139 in repr_instance
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 62 in repr1
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 52 in repr
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 40 in <genexpr>
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 40 in _format_args_and_kwargs
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 56 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 47 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 23 in _format_callback_source
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 32 in format_cb
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 37 in _format_callbacks
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 76 in _future_repr_info
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 139 in repr_instance
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 62 in repr1
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 52 in repr
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 38 in <genexpr>
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 38 in _format_args_and_kwargs
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 56 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 23 in _format_callback_source
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/events.py", line 51 in _repr_info
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/events.py", line 61 in __repr__
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 139 in repr_instance
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 62 in repr1
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 52 in repr
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 40 in <genexpr>
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 40 in _format_args_and_kwargs
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 56 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 47 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 23 in _format_callback_source
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 32 in format_cb
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 37 in _format_callbacks
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 76 in _future_repr_info
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 139 in repr_instance
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 62 in repr1
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 52 in repr
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 38 in <genexpr>
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 38 in _format_args_and_kwargs
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 56 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 23 in _format_callback_source
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/events.py", line 51 in _repr_info
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/events.py", line 61 in __repr__
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 139 in repr_instance
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 62 in repr1
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 52 in repr
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 40 in <genexpr>
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 40 in _format_args_and_kwargs
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 56 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 47 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 23 in _format_callback_source
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 32 in format_cb
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 37 in _format_callbacks
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 76 in _future_repr_info
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 139 in repr_instance
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 62 in repr1
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 52 in repr
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 38 in <genexpr>
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 38 in _format_args_and_kwargs
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 56 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 23 in _format_callback_source
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/events.py", line 51 in _repr_info
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/events.py", line 61 in __repr__
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 139 in repr_instance
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 62 in repr1
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 52 in repr
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 40 in <genexpr>
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 40 in _format_args_and_kwargs
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 56 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 47 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 23 in _format_callback_source
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 32 in format_cb
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 37 in _format_callbacks
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/base_futures.py", line 76 in _future_repr_info
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 139 in repr_instance
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 62 in repr1
  File "/root/miniconda3/envs/omicron/lib/python3.9/reprlib.py", line 52 in repr
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 38 in <genexpr>
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 38 in _format_args_and_kwargs
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 56 in _format_callback
  File "/root/miniconda3/envs/omicron/lib/python3.9/asyncio/format_helpers.py", line 23 in _format_callback_source
```

the code cause problem is as following:
```
class TestSyncJobs(unittest.IsolatedAsyncioTestCase):
    async def asyncSetUp(self) -> None:
        init_test_env()

        await emit.start(engine=emit.Engine.REDIS, dsn=cfg.redis.dsn, start_server=True, heart_beat=1)

        await self.create_quotes_fetcher()

        # if we add the following line, the issue will gone
        # await asyncio.sleep(0.01)
        await omicron.init(aq)
```

sorry the code is not runnable. If you need more info, please tell us what and how to collect.

or if you would like to reproduce the issue by yourself, please try this branch: https://github.com/zillionare/omega/tree/zillionare/issue46
msg410083 - (view) Author: Nikita Sobolev (sobolevn) * (Python triager) Date: 2022-01-08 08:46
Just to clarify.

What do you mean by "When running code in debug mode"?
Do you use some debugger like `pdb` or pycharm?
msg410133 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-01-09 07:04
I guess applying '@reprlib.recursive_repr' decorator to 'events.Handle.__repr__()' function can help.

Could you check, please?
msg410545 - (view) Author: aaron (zillionare) Date: 2022-01-14 06:50
"When running code in debug mode" means we're debug the code. We have used both vscode and pycharm. Same result.
msg410546 - (view) Author: aaron (zillionare) Date: 2022-01-14 06:53
'@reprlib.recursive_repr' decorator to 'events.Handle.__repr__()'

could you tell me which file should I change? and why?
msg415460 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2022-03-17 23:32
Fixed by #47039
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90381
2022-03-17 23:32:50asvetlovsetstatus: open -> closed
superseder: Normalize asyncio future and task repr()
messages: + msg415460

resolution: duplicate
stage: resolved
2022-01-14 06:53:02zillionaresetmessages: + msg410546
2022-01-14 06:50:31zillionaresetmessages: + msg410545
2022-01-09 07:56:38kumaradityasetnosy: + kumaraditya
2022-01-09 07:04:24asvetlovsetmessages: + msg410133
versions: + Python 3.10, Python 3.11
2022-01-08 08:46:09sobolevnsetnosy: + sobolevn
messages: + msg410083
2022-01-07 18:51:11terry.reedysetnosy: + asvetlov, yselivanov
components: + asyncio
2022-01-02 03:36:04zillionarecreate