Skip to content

Instantly share code, notes, and snippets.

Last active Jun 27, 2022
What would you like to do?
python "breakpoint" (more or less equivalent to ruby's binding.pry); for a proper debugger, use
import code; code.interact(local=dict(globals(), **locals()))
Copy link

mach-kernel commented Mar 9, 2016

@obfusk is there any way to halt execution? Trying to use this in a complex Hadoop streaming script and it floods its own stdin with whatever was queued up for stdout.

I've been using either sleep or signal but I'm floored that there isn't a better way to do this.

Copy link

abevoelker commented Apr 25, 2016

If you want to be able to reference imported modules, try this variation:

import code; code.interact(local=dict(globals(), **locals()))

Copy link

mmcintyre123 commented Dec 1, 2016

Brilliant! Thanks for posting.

Copy link

moritzbe commented Mar 23, 2017

thumbs up!

Copy link

adrianobarroso commented Jul 29, 2017


Copy link

bcaccinolo commented Aug 5, 2017

pip install ipdb

import ipdb; ipdb.set_trace()

Copy link

telwell commented Feb 19, 2018

Just wanted to say that I love this snippet ❤️

Copy link

ianmiell commented May 16, 2018

Me too <3

Copy link

reisner commented Jul 27, 2018

The best thing about this snippet is how intuitive it is.

Copy link

crajcan commented Aug 19, 2018

How do I continue execution when I want to exit the interpreter?

Copy link

cantorman commented Sep 29, 2018

@crajcan you probably figured this out, so for those who come later, ^D seems to continue execution.

Copy link

tasaif commented Feb 7, 2019

I wonder if maybe this should be saved somewhere besides a gist

Copy link

charterchap commented Aug 8, 2019

Copy link

jecompton commented Jan 14, 2020

@charterchap No. ^D continues execution, exit() terminates completely.

Copy link

moritzbe commented May 29, 2020

perfect! Its a standard in my work ;)

Copy link

vsuzdaltsev commented Sep 8, 2020

import ipdb; ipdb.set_trace()


Copy link

anahimana commented Oct 12, 2020

Amazing! Thank you!

Copy link

engr-hasanuzzaman commented Jan 16, 2021

It was very helpful to me.

Copy link

ppanchal97 commented Mar 3, 2021


Copy link

hieuns-0318 commented Mar 23, 2021

Very helpful, thank you 👍 !

Copy link

zuhrig commented Apr 8, 2021

still searching for this

Copy link

TimB0 commented May 27, 2021

i dont see how to use do i view the data in my object? is it the same commands as pdb?

Copy link

obfusk commented Jun 4, 2021

i dont see how to use do i view the data in my object? is it the same commands as pdb?

@TimB0 The same way you would in an interactive Python shell :)

$ python3 -c 'x = 42; import code; code.interact(local=dict(globals(), **locals()))'
>>> x

(and when you're done, use ^D (EOF) to continue or quit() to abort the program)

Copy link

charterchap commented Sep 3, 2021

def pry():
    import inspect
    frame = inspect.currentframe().f_back
        import code; 
        code.interact(local=dict(frame.f_globals, **frame.f_locals))
        del frame

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment