Python Forum
Run function in parallel but inherite dynamic data from the previous function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run function in parallel but inherite dynamic data from the previous function
#1
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; https://stackoverflow.com/questions/7207...n-parallel, https://stackoverflow.com/questions/2054...-in-python
Thank you! Please tell me if something sounds obscure
Reply


Messages In This Thread
Run function in parallel but inherite dynamic data from the previous function - by atizva - Jul-10-2018, 10:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  The function of double underscore back and front in a class function name? Pedroski55 9 605 Feb-19-2024, 03:51 PM
Last Post: deanhystad
  Create a function for writing to SQL data to csv mg24 4 1,147 Oct-01-2022, 04:30 AM
Last Post: mg24
  Showing an empty chart, then input data via function kgall89 0 972 Jun-02-2022, 01:53 AM
Last Post: kgall89
  How to insert different types of data into a function DrData82 0 1,243 Feb-10-2022, 10:41 PM
Last Post: DrData82
Information Estimating transfer function from frd data ymohammadi 0 1,436 Feb-10-2022, 10:00 AM
Last Post: ymohammadi
  Flask dynamic data ? korenron 10 7,067 Nov-17-2021, 07:37 AM
Last Post: korenron
  Exit function from nested function based on user input Turtle 5 2,889 Oct-10-2021, 12:55 AM
Last Post: Turtle
  Retrieving a column from a data set using a function Bayle 6 2,325 Oct-06-2021, 08:52 PM
Last Post: Bayle
  Help with WebSocket reading data from anoter function korenron 0 1,324 Sep-19-2021, 11:08 AM
Last Post: korenron
Question Stopping a parent function from a nested function? wallgraffiti 1 3,656 May-02-2021, 12:21 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020