Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 177dd80

Browse files
committed
Experimental version writes the command to a file.
1 parent babe2bf commit 177dd80

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

Lib/bdb.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# and 'wdb', a window-oriented debugger.
77
# And of course... you can roll your own!
88

9+
910
import sys
1011

1112
BdbQuit = 'bdb.BdbQuit' # Exception to give up completely
@@ -220,9 +221,8 @@ def get_stack(self, f, t):
220221
# a debugger to debug a statement, given as a string.
221222

222223
def run(self, cmd):
223-
import __main__
224-
dict = __main__.__dict__
225-
self.runctx(cmd, dict, dict)
224+
modname = self.writetempfile(cmd)
225+
self.runctx('import ' + modname + '\n', {}, {})
226226

227227
def runctx(self, cmd, globals, locals):
228228
self.reset()
@@ -237,6 +237,18 @@ def runctx(self, cmd, globals, locals):
237237
del sys.trace
238238
# XXX What to do if the command finishes normally?
239239

240+
def writetempfile(self, cmd):
241+
import os
242+
modname = 'bdb' + `os.getpid()`
243+
filename = '/tmp/' + modname + '.py'
244+
f = open(filename, 'w')
245+
f.write(cmd + '\n')
246+
f.close()
247+
import sys
248+
if sys.modules.has_key(modname): del sys.modules[modname]
249+
if '/tmp' not in sys.path: sys.path.insert(0, '/tmp')
250+
return modname
251+
240252

241253
# -------------------- testing --------------------
242254

0 commit comments

Comments
 (0)