Oct-16-2017, 02:34 AM
(This post was last modified: Oct-16-2017, 02:35 AM by nexusfactor.)
I'm working on a backup script for home use and at the same time learn threading. I was researching about threads and sharing data across threads. All my research lead to queues, and I found examples from the Python documentation and Google. Here is the best I can come up with.
Purpose:
Read data in from a text file in a separate thread and return it to the main thread for displaying.
Problem:
When printing, it prints the text with brackets. For example, KeePass is the text stored in the file, it prints it like this:
['KeePass']
How can I remove the brackets? I need to work with the values in other methods
Purpose:
Read data in from a text file in a separate thread and return it to the main thread for displaying.
Problem:
When printing, it prints the text with brackets. For example, KeePass is the text stored in the file, it prints it like this:
['KeePass']
How can I remove the brackets? I need to work with the values in other methods
import threading import queue def construct_list(read_file, backup): with open(read_file) as read_obj: backup.put(read_obj.readlines()) backup.task_done() backup_list = queue.Queue() read_thread = threading.Thread(target=construct_list, args=("list.txt", backup_list,)) read_thread.start() read_thread.join() while backup_list.empty() is False: print(backup_list.get())