我正在尝试在 Eclipse/PyDev 中调试 python 脚本,但是当从开发环境中运行时,我似乎无法让脚本正确执行。
Eclipse/PyDev 环境似乎限制了对正在调试的程序的命令行工具的访问。
我如何绕过这个限制?有没有办法在 Eclipse 项目中添加对相关命令行工具的引用?
更新:
这是尝试运行外部应用程序的代码块。这个问题可能与那里的子线程有关吗?
def call_command_in_dir_unix(app, args, targetdir):
# this is the unix implementation
(r,w) = os.pipe()
pid = os.fork()
if pid == -1:
return 'could not fork'
if pid == 0:
# child
print "child!"
os.close(r)
os.dup2(os.open("/dev/null", os.O_WRONLY), 0)
os.dup2(w, 1)
os.dup2(w, 2)
os.chdir(targetdir)
os.environ['openin_any'] = 'p'
os.environ['openout_any'] = 'p'
os.environ['shell_escape'] = 'f'
import resource
resource.setrlimit(resource.RLIMIT_CPU,
(MAX_RUN_TIME * 1000, MAX_RUN_TIME * 1000)) # docs say this is seconds, but it is msecs on my system.
# os.execvp will raise an exception if the executable isn't
# present. [[ try os.execvp("aoeu", ['aoeu']) ]]
# If we don't catch exceptions here, it will be caught at the
# main body below, and then os.rmdir(tmpdir) will be called
# twice, once for each fork. The second one raises an exception
# in the main code, which gets back to the user. This is bad.
try:
os.execvp(app, [app] + list(args))
finally:
print "failed to exec()",app
os._exit(2)
else:
# parent
os.close(w)
r = os.fdopen(r,"r")
output = ''.join(r.readlines())
(npid, exi) = os.waitpid(pid, 0)
r.close()
sig = exi & 0xFF
stat = exi >> 8
if stat != 0 or sig != 0:
return ' error! exitcode was %d (signal %d), transscript follows:\n\n%s' % (stat,sig,output)
return None
# notreached