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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:16:51+00:00 2026-05-27T11:16:51+00:00

If I run a code with the ipython %pdb magic enabled and the code

  • 0

If I run a code with the ipython %pdb magic enabled and the code throws an exception, is there any way to tell the code to continue executing afterwards?

e.g., say the exception is a ValueError: x=0 not allowed. Can I, in pdb, set x=1 and allow the code to continue (resume) executing?

  • 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-27T11:16:51+00:00Added an answer on May 27, 2026 at 11:16 am

    I don’t think you can resume code post-mortem (i.e. the exception was actually raised, triggering invocation of the debugger). What you can do, is put breakpoints in your code where you have been seeing errors, and that allows you to change values, and continue the program avoiding the error.

    Given a script myscript.py:

    # myscript.py
    from IPython.core.debugger import Tracer
    
    # a callable to invoke the IPython debugger. debug_here() is like pdb.set_trace()
    debug_here = Tracer()
    
    def test():
        counter = 0
        while True:
            counter += 1
            if counter % 4 == 0:
                 # invoke debugger here, so we can prevent the forbidden condition
                debug_here()
            if counter % 4 == 0:
                raise ValueError("forbidden counter: %s" % counter)
    
            print counter
    
    test()
    

    Which continually increments a counter, raising an error if it’s ever divisible by 4. But we have edited it to drop into the debugger under the error condition, so we might be able to save ourselves.

    Run this script from IPython:

    In [5]: run myscript
    1
    2
    3
    > /Users/minrk/dev/ip/mine/myscript.py(14)test()
         13             debug_here()
    ---> 14         if counter % 4 == 0:
         15             raise ValueError("forbidden counter: %s" % counter)
    
    # increment counter to prevent the error from raising:
    ipdb> counter += 1
    # continue the program:
    ipdb> continue
    5
    6
    7
    > /Users/minrk/dev/ip/mine/myscript.py(13)test()
         12              # invoke debugger here, so we can prevent the forbidden condition
    
    ---> 13             debug_here()
         14         if counter % 4 == 0:
    
    # if we just let it continue, the error will raise
    ipdb> continue
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    IPython/utils/py3compat.pyc in execfile(fname, *where)
        173             else:
        174                 filename = fname
    --> 175             __builtin__.execfile(filename, *where)
    
    myscript.py in <module>()
         17         print counter
         18 
    ---> 19 test()
    
    myscript.py in test()
         11         if counter % 4 == 0:
         12              # invoke debugger here, so we can prevent the forbidden condition
    
         13             debug_here()
         14         if counter % 4 == 0:
    ---> 15             raise ValueError("forbidden counter: %s" % counter)
    
    ValueError: forbidden counter: 8
    
    In [6]:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to run code when COM object is about to be
I am using iPython to run my code. I wonder if there is any
Is there a way to run code BEFORE model retrieval? I know about the
There must be simple way, I do not want to run Code Analysis separately
is there some way to run code on termination, no matter what kind termination
Using the built-in Ruby Minitest framework, is there a way to run some code
When I run this code, About half-way through the concatenation loop, $xml becomes null
What is the best way to run code on a separate thread? Is it:
I'm looking for a way to transparently run code when a class is defined
how can i run code when an application ends with asp.net mvc ?

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.