我有以下代码:
import sys
def entry_point(argv):
sys.exit(1)
return 0
def target(*args):
return entry_point, None但是,当我运行python ./pypy/pypy/translator/goal/translate.py t.py时,我得到以下错误:
...
[translation:ERROR] Exception: unexpected prebuilt constant: <built-in function exit>
[translation:ERROR] Processing block:
[translation:ERROR] block@9 is a <class 'pypy.objspace.flow.flowcontext.SpamBlock'>
[translation:ERROR] in (t:3)entry_point
[translation:ERROR] containing the following operations:
[translation:ERROR] v0 = simple_call((builtin_function_or_method exit), (1))
[translation:ERROR] --end--实际上还有更多的错误,但我认为只有最后这部分是相关的。如果你认为更多的可能是有帮助的,请评论,我将编辑。
事实上,当我用像sys.stdout.write这样更简单的东西替换sys.exit时,我得到了另一个错误。
import sys
def entry_point(argv):
sys.stdout.write('some mesg\n')
return 0
def target(*args):
return entry_point, None给了我:
...
[translation:ERROR] AnnotatorError: annotation of v0 degenerated to SomeObject()
[translation:ERROR] v0 = getattr((module sys), ('stdout'))
[translation:ERROR]
[translation:ERROR] In <FunctionGraph of (t:3)entry_point at 0x10d03de10>:
[translation:ERROR] Happened at file t.py line 4
[translation:ERROR]
[translation:ERROR] ==> sys.stdout.write('some mesg\n')
[translation:ERROR]
[translation:ERROR] Previous annotation:
[translation:ERROR] (none)
[translation:ERROR] Processing block:
[translation:ERROR] block@3 is a <class 'pypy.objspace.flow.flowcontext.SpamBlock'>
[translation:ERROR] in (t:3)entry_point
[translation:ERROR] containing the following operations:
[translation:ERROR] v0 = getattr((module sys), ('stdout'))
[translation:ERROR] v1 = getattr(v0, ('write'))
[translation:ERROR] v2 = simple_call(v1, ('some mesg\n'))
[translation:ERROR] --end--sys方法是RPython的禁区吗?这对我来说似乎有点奇怪,因为exit和stdout在C中非常容易使用。然而,错误消息看起来可能是关于不同的事情,所以我可能只是在错误的树上运行。
目前,我正在使用this指南来大致了解在RPython中允许和不允许的内容。有没有其他比较容易获得的参考资料,我可以用来获取更多信息?
发布于 2012-02-12 06:37:15
系统模块不是RPython,您不能在RPython程序中使用它。要返回状态代码,必须直接从entry_point函数返回它。
您也不能使用sys.stdout/sys.stdin/sys.stderr,您需要使用os.read/os.write函数结合文件描述符进行读/写。
https://stackoverflow.com/questions/9239050
复制相似问题