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 6161025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:24:53+00:00 2026-05-23T21:24:53+00:00

I am putting together a small debugger for python so I can basically attach

  • 0

I am putting together a small debugger for python so I can basically attach in the middle of the program and pause the code or break when some variable changes or step one line, etc… basically pdb but with attaching (so more like gdb assuming pystack isn’t working).

For a single thread, one can do sys.settrace(), for a multithreaded program, assuming no threads have started, one can do threading.settrace(), but the problem is that you are stuck debugging the whole thing (or doing it at a specific point in a specific thread) as far as I know.

I was wondering if there is a way to do something like sys.settrace() in python for a particular different thread that has already started?

  • 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-05-23T21:24:53+00:00Added an answer on May 23, 2026 at 9:24 pm

    ok, it doesn’t seem quite possible to do this.

    The closest I got was hearing about thread2 (killable threads), which calls PyThreadState_SetAsyncExc, which raises an exception, and the constructor is called in the other thread, which is rather useless.

    My solution is going to not use sys.settrace at all, but instead just use sys.setcheckinterval to set it to 1 for when I leave my debugging thread, and back to some huge number (sys.maxint maybe) when I enter the debug thread (along with grabbing the GIL). Along with looking at sys._current_frames().

    This is nearly as good as sys.settrace, maybe slower, but can be run against any thread at any time for any duration.

    edit:

    First – I’ve found out that doing setcheckinterval is insufficient for stopping other threads, though it can be done for particular python versions to some extent by setting the global _Py_Ticker (in ceval.c and not a static global, so you can use ctypes) and making sure you don’t release the GIL in your code.

    w.r.t. the original problem, I looked thru the c code in CPython and found a way to traverse the thread state objects and adjust them to include a tracefunc and traceobj; you can see how I do it in my debugger here — https://github.com/bobfrank/pydebug/blob/master/debug.py#L291

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

Sidebar

Related Questions

I'm putting together a small program in Visual Basic Express 2010, and part of
I'm putting together a small web app that writes to a database (Perl CGI
I am putting together some ideas for our automated testing platform and have been
I am putting together an Java application that needs to display some basic lab
I'm putting together my deployment plan for a major deployment next week (basically taking
I'm parsing various site feeds, and putting together a small library to help me
I am putting together a small app that has a leaderboard concept in it.
I am putting together a program that will calculate the area of either a
I am putting together an explanation and code example of this design pattern, attempting
I've been putting together an auditing solution for a program I am developing, where

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.