一个大型实体(列表)在一个方法 ( foo
) 中创建并绑定到self.result
。尝试在第二种方法 ( transmit
) 中访问该实体的尝试从某个大小(列表中的 150,000 到 155,000 个字符)开始失败。打印(print self.result)
从内部transmit
给我留下了无。我想这很重要:self.foo
在单独的线程中直接调用。
请帮助。如何在没有这种限制的情况下将这样的“大”实体从单独的线程返回到主线程?
...
def apply(self):
self.get_data()
self.start_foo_thread()
def start_foo_thread(self):
self.foo_thread = threading.Thread(target=self.foo)
self.foo_thread.daemon = True
self.progressbar.start()
self.foo_thread.start()
self.master.after(20, self.check_foo_thread)
def check_foo_thread(self):
if self.foo_thread.is_alive():
self.master.after(20, self.check_foo_thread)
else:
self.progressbar.stop()
def foo(self):
s = self.stringinput
n = self.numberinput
list = multiply_str_into_list(s, n)
self.result = list_to_text(list)
print self.result # output is not None
def transmit(self):
print self.result # output is None for more than about 155,000 characters in the list
return self.result
def multiply_str_into_list(string, n): #takes a string and multiplies it by n and writes into list
n_string = []
for i in range(0,n):
n_string.append(string)
return n_string
def list_to_text(list): #takes a list as input and joins it into str with each list item on a new line
a = '\n'.join(list)
return a