A large entity (list) is created in one method (foo
) and bound to self.result
.
The attempt to access this entity in a second method (transmit
) fails starting at a certain size (something between 150,000 and 155,000 characters in the list). Printing (print self.result)
from inside transmit
leaves me with None.
I guess this is important: self.foo
is directly called in a separate thread.
Please help. How do I get such "large" entity from a separate thread back into the main thread without such limitation?
...
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
list
andstring
because those are already used for built-in types or modules and doing so can cause unintended side-effects, as well as make it hard for others to read. It can also make debugging harder. – Unpopular