在 Jython 中使用检查.py 时出现问题
我正在使用用 Jython 开发的应用程序。 当我尝试在其中使用 inform.py 时,它会显示错误消息。
我的代码是这样的
import inspect,os,sys,pprint,imp
def handle_stackframe_without_leak(getframe):
frame = inspect.currentframe()
try:
function = inspect.getframeinfo(getframe)
print inspect.getargvalues(getframe)
finally:
del frame
#
def raja(a):
handle_stackframe_without_leak(inspect.currentframe())
print a
#
def callraja():
handle_stackframe_without_leak(inspect.currentframe())
raja("[email protected]")
#
callraja()
raja("[email protected]")
#
当我使用 python.exe 运行它时,没有任何问题。 但是,在应用程序内使用它会引发以下错误
File "C:\Program Files\jython221ondiffjava\Lib\inspect.py", line 722, in getframeinfo
File "C:\Program Files\jython221ondiffjava\Lib\inspect.py", line 413, in findsource
File "C:\Program Files\jython221ondiffjava\Lib\sre.py", line 179, in compile
File "C:\Program Files\jython221ondiffjava\Lib\sre.py", line 227, in _compile
File "C:\Program Files\jython221ondiffjava\Lib\sre_compile.py", line 437, in compile
File "C:\Program Files\jython221ondiffjava\Lib\sre_compile.py", line 421, in _code
File "C:\Program Files\jython221ondiffjava\Lib\sre_compile.py", line 143, in _compile
ValueError: ('unsupported operand type', 'branch')
at org.python.core.Py.makeException(Unknown Source)
at sre_compile$py._compile$1(C:\Program Files\jython221ondiffjava\Lib\sre_compile.py:143)
at sre_compile$py.call_function(C:\Program Files\jython221ondiffjava\Lib\sre_compile.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at sre_compile$py._code$11(C:\Program Files\jython221ondiffjava\Lib\sre_compile.py:421)
at sre_compile$py.call_function(C:\Program Files\jython221ondiffjava\Lib\sre_compile.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at sre_compile$py.compile$12(C:\Program Files\jython221ondiffjava\Lib\sre_compile.py:437)
at sre_compile$py.call_function(C:\Program Files\jython221ondiffjava\Lib\sre_compile.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at org.python.core.PyObject.invoke(Unknown Source)
at sre$py._compile$13(C:\Program Files\jython221ondiffjava\Lib\sre.py:227)
at sre$py.call_function(C:\Program Files\jython221ondiffjava\Lib\sre.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at sre$py.compile$8(C:\Program Files\jython221ondiffjava\Lib\sre.py:179)
at sre$py.call_function(C:\Program Files\jython221ondiffjava\Lib\sre.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at org.python.core.PyObject.invoke(Unknown Source)
at inspect$py.findsource$24(C:\Program Files\jython221ondiffjava\Lib\inspect.py:413)
at inspect$py.call_function(C:\Program Files\jython221ondiffjava\Lib\inspect.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at inspect$py.getframeinfo$54(C:\Program Files\jython221ondiffjava\Lib\inspect.py:722)
at inspect$py.call_function(C:\Program Files\jython221ondiffjava\Lib\inspect.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at org.python.core.PyObject.invoke(Unknown Source)
at custom$py.handle_stackframe_without_leak$4(C:\Program Files\<my app>\jars\custom.py:29)
at custom$py.call_function(C:\Program Files\<my app>\.\jars\custom.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at definitions$py.gotonotificationprofile$122(C:\Program Files\<my app>\.\jars\definitions.py:1738)
at definitions$py.call_function(C:\Program Files\<my app>\.\jars\definitions.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at notificationcases$py.A003$2(C:\Program Files\<my app>\.\jars\notificationcases.py:143)
at notificationcases$py.call_function(C:\Program Files\<my app>\.\jars\notificationcases.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at org.python.pycode._pyx171.f$0(003:8)
at org.python.pycode._pyx171.call_function(003)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyCode.call(Unknown Source)
at org.python.core.Py.runCode(Unknown Source)
at org.python.util.PythonInterpreter.execfile(Unknown Source)
任何帮助将不胜感激。
谢谢 拉贾桑卡
I am using an application developed in Jython. When I try to use the inspect.py in that, it shows error message.
My code goes like this
import inspect,os,sys,pprint,imp
def handle_stackframe_without_leak(getframe):
frame = inspect.currentframe()
try:
function = inspect.getframeinfo(getframe)
print inspect.getargvalues(getframe)
finally:
del frame
#
def raja(a):
handle_stackframe_without_leak(inspect.currentframe())
print a
#
def callraja():
handle_stackframe_without_leak(inspect.currentframe())
raja("[email protected]")
#
callraja()
raja("[email protected]")
#
When I run this using python.exe, there are no issues. However, using this inside the app throwing the following error
File "C:\Program Files\jython221ondiffjava\Lib\inspect.py", line 722, in getframeinfo
File "C:\Program Files\jython221ondiffjava\Lib\inspect.py", line 413, in findsource
File "C:\Program Files\jython221ondiffjava\Lib\sre.py", line 179, in compile
File "C:\Program Files\jython221ondiffjava\Lib\sre.py", line 227, in _compile
File "C:\Program Files\jython221ondiffjava\Lib\sre_compile.py", line 437, in compile
File "C:\Program Files\jython221ondiffjava\Lib\sre_compile.py", line 421, in _code
File "C:\Program Files\jython221ondiffjava\Lib\sre_compile.py", line 143, in _compile
ValueError: ('unsupported operand type', 'branch')
at org.python.core.Py.makeException(Unknown Source)
at sre_compile$py._compile$1(C:\Program Files\jython221ondiffjava\Lib\sre_compile.py:143)
at sre_compile$py.call_function(C:\Program Files\jython221ondiffjava\Lib\sre_compile.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at sre_compile$py._code$11(C:\Program Files\jython221ondiffjava\Lib\sre_compile.py:421)
at sre_compile$py.call_function(C:\Program Files\jython221ondiffjava\Lib\sre_compile.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at sre_compile$py.compile$12(C:\Program Files\jython221ondiffjava\Lib\sre_compile.py:437)
at sre_compile$py.call_function(C:\Program Files\jython221ondiffjava\Lib\sre_compile.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at org.python.core.PyObject.invoke(Unknown Source)
at sre$py._compile$13(C:\Program Files\jython221ondiffjava\Lib\sre.py:227)
at sre$py.call_function(C:\Program Files\jython221ondiffjava\Lib\sre.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at sre$py.compile$8(C:\Program Files\jython221ondiffjava\Lib\sre.py:179)
at sre$py.call_function(C:\Program Files\jython221ondiffjava\Lib\sre.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at org.python.core.PyObject.invoke(Unknown Source)
at inspect$py.findsource$24(C:\Program Files\jython221ondiffjava\Lib\inspect.py:413)
at inspect$py.call_function(C:\Program Files\jython221ondiffjava\Lib\inspect.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at inspect$py.getframeinfo$54(C:\Program Files\jython221ondiffjava\Lib\inspect.py:722)
at inspect$py.call_function(C:\Program Files\jython221ondiffjava\Lib\inspect.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at org.python.core.PyObject.invoke(Unknown Source)
at custom$py.handle_stackframe_without_leak$4(C:\Program Files\<my app>\jars\custom.py:29)
at custom$py.call_function(C:\Program Files\<my app>\.\jars\custom.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at definitions$py.gotonotificationprofile$122(C:\Program Files\<my app>\.\jars\definitions.py:1738)
at definitions$py.call_function(C:\Program Files\<my app>\.\jars\definitions.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at notificationcases$py.A003$2(C:\Program Files\<my app>\.\jars\notificationcases.py:143)
at notificationcases$py.call_function(C:\Program Files\<my app>\.\jars\notificationcases.py)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyFunction.__call__(Unknown Source)
at org.python.pycode._pyx171.f$0(003:8)
at org.python.pycode._pyx171.call_function(003)
at org.python.core.PyTableCode.call(Unknown Source)
at org.python.core.PyCode.call(Unknown Source)
at org.python.core.Py.runCode(Unknown Source)
at org.python.util.PythonInterpreter.execfile(Unknown Source)
Any help will be appreciated.
Thanks
Rajasankar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过使用 Jython 在命令行上运行您的程序(因此在应用程序之外)? 当我使用 Jython 2.2.1 或 Jython 2.5.0 运行您的程序时,我得到与 Python 相同的输出。
Have you tried running your program on the command line with Jython (so outside of the app)? When I run your program with Jython 2.2.1 or Jython 2.5.0, I get identical output as from Python.
这可能会有所帮助 http://grinder.sourceforge.net/faq.html#re-problems 。
为了快速检查,请尝试在 findsource 方法中添加
import re
(C:\Program Files\jython221ondiffjava\Lib\inspect.py),但不能承诺任何事情。 。
This might help http://grinder.sourceforge.net/faq.html#re-problems.
For a quick check, try adding
import re
in findsource method (C:\Program Files\jython221ondiffjava\Lib\inspect.py)Can't promise anything, though...