python - 从python中的另一个线程更改为主线程
问题描述
例如,有没有办法从后台线程转移到主线程;
import threading
def func(txt):
if txt == 'foo':
## must do the processing in the main thread
pass
else:
print(txt)
thread = threading.Thread(target = func, args = ('hello',))
thread.start()
提前致谢 :)
解决方案
您可以在主线程中有一个变量,该变量将在 func 中更改。然后检查 main 变量的状态。
如果 foo,那么做点什么。
推荐阅读
- wpf - 使用带有 IsNavigationTarget 的 Prism 处理嵌套视图,可以返回 false
- regex - 匹配只有两个结束字符的域的正则表达式?
- spring - BeanDefinitionStoreException: 无法解析配置类...因为它不存在
- c++ - 使用列表初始化器与构造器的复杂<>?
- azure - 相同操作的 Powershell cmdlet 差异
- java - Java 递归 - 基于子属性捕获父类别
- python - 使用数据框绘制子图
- linux - 如果命令超过 1 行,如何在 shell 或 bash 中输入新行/移动到下一行而不执行命令?
- linux - 如何解冻用户的内存限制?
- reactjs - 美人鱼类图的自定义箭头