I'm trying to run multiple functions simultaneously:
-or so called functions because they belong to a class:
from sh import tail
data = {}
class my_Class():
def __init__(self):
"""Nothing to declare for initializing"""
def get_data(self, filepath):
"""I'm trying to import the data from several files"""
for line in tail("-f", "-n 1", filepath, _iter=True):
data[filepath] = line
print(data)
my_Class().get_data("path/to/file") #call 1
my_Class().get_data("path/to/another/file") #call 2
# ... 14 similar calls
I want each call to append it's data to the dictionary. And so, when I call:
my_Class().get_data("path/to/file") #call 1
my_Class().get_data("path/to/another/file") #call 2
# ... 14 similar calls
The result should print:
#1 {'filepath1' : line}
#2 {'filepath1' : line, 'filepath2' : line}
#3 {'filepath1' : line, 'filepath2' : line, 'filepath3' : line}
# ... 13 more
At the same time I want the content of dictionary data{...} to keep changing dynamically; because of the data in the files is flexible. For example:
#1 {'filepath1' : line}
#2 {'filepath1' : last_line_in_the_file}, 'filepath2' : line}
#3 {'filepath1' : last_line_in_the_file, 'filepath2' : last_line_in_the_file, 'filepath3' : line}
# ... 13 more
I've already checked these posts: but it doesn't do what I ask; Python: How can I run python functions in parallel?, How to do parallel programming in Python Thank you! Please tell me if something sounds obscure