简体   繁体   English

暂停嵌入式python脚本执行

[英]suspend embedded python script execution

I have an app that embeds python scripting. 我有一个嵌入python脚本的应用程序。

I'm adding calls to python from C, and my problem is that i need to suspend the script execution let the app run, and restore the execution from where it was suspended. 我正在从C添加对python的调用,我的问题是我需要挂起脚本执行程序才能让应用程序运行,并从挂起的位置恢复执行。

The idea is that python would call, say "WaitForData" function, so at that point the script must suspend (pause) the calls bail out so the app event loop would continue. 这个想法是python会调用“ WaitForData”函数,因此该脚本必须暂停(暂停)调用,以确保应用程序事件循环继续进行。 When the necessary data is present, i would like to restore the execution of the script, it is like the python call returns at that point. 当必要的数据存在时,我想恢复脚本的执行,就像python调用在那时返回一样。

i'm running single threaded python. 我正在运行单线程python。

any ideas how can i do this, or something similar, where i'll have the app event loop run before python call exits? 任何想法我该怎么做,或类似的东西,我将在python调用退出前运行应用程序事件循环?

Well, the only way I could come up with is to run the Python engine on a separate thread. 好吧,我唯一能想到的方法是在单独的线程上运行Python引擎。 Then the main thread is blocked when the python thread is running. 然后,当python线程运行时,主线程被阻塞。

When I need to suspend, I block the Python thread, and let the main thread run. 当我需要挂起时,我阻塞Python线程,然后让主线程运行。 When necessary, the OnIdle of the main thread, i block it and let the python continue. 必要时,我将主线程的OnIdle阻塞,并让python继续运行。

it seems to be working fine. 它似乎工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM