-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cant 't call pyfunc in async mode #45
Comments
This may be related to boostorg/python#374, wherein certain Boost operations in C++ destructors can cause the interpreter to bug out in an You could check whether or not that is the case by forcing destruction of your locals before returning from the async function, like so: def _inner():
ctx = v8py.Contenxt()
ctx.expose(Test)
ctx.eval("""test = new Test()""")
ctx.eval("""
test.sync_func()
""")
async def main():
_inner()
print("main end...") If that solves the problem, you may be affected by the linked issue (and you should mention that in its comments!). If not, something else is likely going on. As an aside, it also looks like your interactions with |
yea, i try you code, it exit normally and not raise exception. |
actually i didn't understand what is the diffrence between the two case |
@RonaldinhoL the issue has to do with when destructors are run. Python garbage collects things (and runs their destructors) when the reference count of an object drops to zero. If you allocate something in a function, when that function returns, that thing's reference count drops to zero and it is garbage collected--this happens in a weird space after the function Normally this works fine. However, if post-return destructors are run in That's about as much as I understand; the issue might be with the way C++ is bound to python in this library, or it might be with Python itself (I filed an issue on boost-python for the former, and one on the Python core for the latter, but I'm not quite sure as to the "why" here, or if either issue is expected behavior).
In the changes I proposed, post-return destruction happens in a synchronous function. In You could also solve the problem by calling |
thanks for your patience and explanation 👍 :) |
if i call py function in async, then will cause exception
StopIteration
The above exception was the direct cause of the following exception:
SystemError: _PyEval_EvalFrameDefault returned a result with an error set
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "xxx\demo.py", line 59, in
asyncio.run(main())
File "C:\Users\xxx.pyenv\pyenv-win\versions\Python-3.9.4\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\xxx.pyenv\pyenv-win\versions\Python-3.9.4\lib\asyncio\base_events.py", line 642, in run_until_complete
return future.result()
SystemError: _PyEval_EvalFrameDefault returned a result with an error set
The text was updated successfully, but these errors were encountered: