Skip to content

Commit 024b6bc

Browse files
authored
gh-156774: Speed up pdb startup with asyncio guard (#156775)
1 parent 465b3b8 commit 024b6bc

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

Lib/pdb.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
import signal
8585
import socket
8686
import typing
87-
import asyncio
8887
import inspect
8988
import weakref
9089
import builtins
@@ -102,6 +101,8 @@
102101
from types import CodeType
103102
from warnings import deprecated
104103

104+
lazy import asyncio
105+
105106
try:
106107
import _pyrepl.utils
107108
except ModuleNotFoundError:
@@ -902,6 +903,10 @@ def _hold_exceptions(self, exceptions):
902903
self._chained_exception_index = 0
903904

904905
def _get_asyncio_task(self):
906+
# If asyncio has never been imported there cannot be a running task,
907+
# so skip the import rather than pay for it on every interaction.
908+
if 'asyncio' not in sys.modules:
909+
return None
905910
try:
906911
task = asyncio.current_task()
907912
except RuntimeError:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Speed up :mod:`pdb` startup by only importing :mod:`asyncio` when the program
2+
being debugged has already imported it.

0 commit comments

Comments
 (0)