[Python]如何在两个线程之间共享变量 [英] [Python]how do I share a variable between two threads

查看:797
本文介绍了[Python]如何在两个线程之间共享变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,在开始从stackoverflow发布链接之前,请先让我解释一下。我有一个脚本(用python ofcourse编写),在其上我从另一个脚本文件(.py)开始一个新方法(作为一个新线程)。现在,我想要的是这两个脚本(或这两个线程)共享一个公共变量。这可能吗?



我尝试了什么:



我尝试过使用此处的队列: python - 如何在2个线程之间共享变量 - 堆栈溢出 [ ^ ]

Ok, before starting to post links from stackoverflow, please first let me explain. I have a script(written in python ofcourse), on which i start a new method(as a new thread) from another script file(.py). Now, what i want is these two scripts(or these two threads) to share one common variable. Is this possible ?

What I have tried:

I tried using queue found here: python - How to share a variable between 2 threads - Stack Overflow[^]

推荐答案

StackOverflow帖子中建议的答案正是您所需要的。
The answer suggested in the StackOverflow post is exactly what you need.


这篇关于[Python]如何在两个线程之间共享变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆