Last active
September 1, 2016 07:11
-
-
Save taojy123/1b76c6a90f791b10b2a6936cd95ee9e8 to your computer and use it in GitHub Desktop.
Python 跨文件跨进程使用全局变量
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abc = None | |
cba = None | |
def set_abc(value): | |
global abc | |
abc = value | |
def get_abc(): | |
global abc | |
return abc | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import globalvar | |
import threading | |
import time | |
import t | |
globalvar.set_abc('123') | |
globalvar.cba = '321' | |
t1 = threading.Thread(target=t.show_data) | |
t1.setDaemon(True) | |
t1.start() | |
time.sleep(1) | |
print 'finish!' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import globalvar | |
def get_data(): | |
print globalvar.get_abc() | |
print globalvar.cba | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment