Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8380401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:26:57+00:00 2026-06-09T16:26:57+00:00

there. I have some code written for Python 3.1 that is misbehaving. If it

  • 0

there.
I have some code written for Python 3.1 that is misbehaving. If it was some C code, I’d just use gdbserverfirst, attach to the process (it’s involved in a fairly sophisticated command line, where the python process receives its input on stdin), fire my favourite GDB front-end and I’ll be ready to figure out why it’s going wrong.

But it’s python. I just tried the pdb module, but I can’t interrupt the process when it goes off: I get a “KeyboardInterrupt” instead (and I need to change the rest of the command chain so that they give set_ptrace a go)

I tried winpdb, which produced curious error message

   Unhandled Exception (in pyshared/rpdb2.py)

and asked for a “password” before I could attach to the process. It gives me the overall feeling that winpdb is for python2 only.

I just tried gdb __main__.py in order to attach to the running process, but that says “format not recognized”, as one could imagine.

Where is the manpage I’ve missed ?

PS: oh, it’s a multi-threaded process, if that matters.

A minimal example:

import pdb

pdb.set_trace()  # press 'c' here to continue
while(True):
    print("hi")  # hit CTRL+C here ... will just kill the program with python 3.1

print("ooh")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:26:59+00:00Added an answer on June 9, 2026 at 4:26 pm

    The typical way of using pdb is to put a line with:

    import pdb;pdb.set_trace()
    

    Where you want the break. If you want the break to be conditional, then you just add the condition, like:

    if x > 1000:
        import pdb;pdb.set_trace()
    

    No CTRL-C is involved.

    However, a CTRL-C hook will be installed if you let the pdb module run the script:

    python3 /path/to/stdlib/pdb.py myscript.py
    

    A shorter and simpler way to write that is:

    python3 -m pdb myscript.py
    

    Some linux distributions will also make a link to pdb.py in /usr/bin, meaning you get it as a command:

    pdb3 myscript.py
    

    All these three commands above do the same thing. That thing is however different from the pdb.set_trace(), as pressing CTRL-C will then enter post-mortem debugging. That means you can’t step through the code as the next step would be exiting the program. It is therefore much less useful than the above technique. It can however be a quick way to figure out what in your code is taking a lot of time, when it is running slow, and it will then allow you to put in a set_trace() in the correct place to figure out why it is slow.

    It does also indeed as you indicate above, seem to be broken in Python 3.1. It does however work in Python 3.2.

    It will only work in simple cases, though, in more complex cases you need to use profiling to find the culprit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that creates a Process instance and later starts it. There's
I have some code that looks like this. There is also an autoincrement field
I have written some C++ code that generates a std::vector. I also have a
I've written some C code that I would like to port to python, as
I have some code to read from a pdf file. Is there a way
I have ace editor integrated in my site. I have some code there, and
In my application there is language detection. Languages have some identification code like en
I have a web application with bunch of HTML code. There are some style-attributes
I am a beginner in Python and I have written this simple code but
I have some software that is heavily dependent on MySQL, and is written in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.