# \`--debug\` flag to pause and print PID for use in debuggers, profilers, etc

**URL:** <https://discuss.python.org/t/debug-flag-to-pause-and-print-pid-for-use-in-debuggers-profilers-etc/108519>\
**Category:** Ideas\
**Created:** [August 11, 2026, 9:39pm UTC](https://discuss.python.org/t/debug-flag-to-pause-and-print-pid-for-use-in-debuggers-profilers-etc/108519 "2026-08-11T21:39:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![edvilme](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/edvilme/32/35395_2.png) [@edvilme](https://discuss.python.org/u/edvilme)\
**Post date:** [August 11, 2026, 9:39pm UTC](https://discuss.python.org/t/debug-flag-to-pause-and-print-pid-for-use-in-debuggers-profilers-etc/108519/1 "2026-08-11T21:39:55Z")

</div>

Similar to other tools, it would be nice when developing CPython to have a good mechanism for debugging.

I think it would be nice to have a `--debug` flag that when passed, prints something like this

```plaintext
Debug Mode
PID XXXX
Press any key to continue...

```

Then, people could copy the PID and paste it into any debugger, profiler, etc that supports it. I think having the program be executed until after the PID is copied can also be useful.

I think having a builtin way of doing this can be very useful to people wanting to get started in making contributions, or simply learning _how_ Python works.

I am not aware if there are similar tools doing this, or if something similar has been proposed/rejected (if it has, would love to learn about it)

---

<div class="post-metadata">

**Author:** ![jonathandung](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jonathandung/32/35459_2.png) [@jonathandung](https://discuss.python.org/u/jonathandung)\
**Post date:** [August 12, 2026, 12:17am UTC](https://discuss.python.org/t/debug-flag-to-pause-and-print-pid-for-use-in-debuggers-profilers-etc/108519/2 "2026-08-12T00:17:03Z")

</div>

If you want to debug your Python program, use `pdb`. But if the process is already running, it can just print `os.getpid()` at some point which you can then attach to with a third-party debugger (`pdb` also has this attaching capability). But Python already has some good built-in profiling tools, so I don’t really see the utility of this.

---

<div class="post-metadata">

**Author:** ![edvilme](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/edvilme/32/35395_2.png) [@edvilme](https://discuss.python.org/u/edvilme)\
**Post date:** [August 12, 2026, 1:04am UTC](https://discuss.python.org/t/debug-flag-to-pause-and-print-pid-for-use-in-debuggers-profilers-etc/108519/3 "2026-08-12T01:04:25Z")

</div>

Yes, I think `pdb` or `os.getpid` are more helpful for those cases. Sorry, I meant to debug python _itself_ rather than other programs.  
E.g., if I run the REPL and want to know the call chain, or profile the import mechanism, etc.

---

<div class="post-metadata">

**Author:** ![jonathandung](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jonathandung/32/35459_2.png) [@jonathandung](https://discuss.python.org/u/jonathandung)\
**Post date:** [August 12, 2026, 3:19am UTC](https://discuss.python.org/t/debug-flag-to-pause-and-print-pid-for-use-in-debuggers-profilers-etc/108519/4 "2026-08-12T03:19:29Z")

</div>

I see. For the import case, you can start python with `-vv` or `-X importtime`. If you want to see call chains, you should use `sys.settrace`.
