Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect that Python code is being executed through the debugger?

Is there a simple way to detect, within Python code, that this code is being executed through the Python debugger?

I have a small Python application that uses Java code (thanks to JPype). When I'm debugging the Python part, I'd like the embedded JVM to be passed debug options too.

like image 543
Stéphane Bonniez Avatar asked Dec 02 '08 13:12

Stéphane Bonniez


1 Answers

Python debuggers (as well as profilers and coverage tools) use the sys.settrace function (in the sys module) to register a callback that gets called when interesting events happen.

If you're using Python 2.6, you can call sys.gettrace() to get the current trace callback function. If it's not None then you can assume you should be passing debug parameters to the JVM.

It's not clear how you could do this pre 2.6.

like image 189
babbageclunk Avatar answered Sep 30 '22 23:09

babbageclunk