0
假装一个有脚本创建一些测试主题:test1.py
取得现有的线程蟒蛇
import threading
import time
class Test(threading.Thread):
def __init__(self, name, alist):
threading.Thread.__init__(self)
self.alist = alist
self.name = name
def run(self):
print "Starting thread " + self.name
self.append_to_alist(self.alist)
print "Exiting thread" + self.name
def append_to_alist(self, alist):
for x in range(5):
self.alist.append(alist[-1]+1)
time.sleep(10)
def main():
alist = [1]
# Create new thread
thread = Test("Test thread", alist)
thread.start()
thread.join()
print alist
main()
现在我运行它python test1.py
,然后我想,以修改现有Test
线程中运行另一个脚本test2.py
这工作时,这样的事情,test2.py
:
import threading
thread = somehow_get_access_to_Test_thread()
thread.alist.append('test')
这可能吗?