Python Forum
Python - Make Json objects to work concurrently through Threads?
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python - Make Json objects to work concurrently through Threads?
#1
What I was planning to do is to have a multiple JSON objects, for example:

    {
        "Profiles": {
            "profile_0": {
    			"Url": "Myownwebsite.se",
    			"My-Note": "Helloworld",
                "Email": "[email protected]"
                "PersonNumber": "1234543",
                "postal_code": "54123",
                "given_name": "World",
                "Last_name": "Hellow",
                "street_address": "helloworld 123",
                "city": "Stockholm",
                "country": "Sweden",
                "phone": "123456789",
				"Color": "Red",
                "house_number": "123",
				"year": "2017"
            },
            "profile_1": {
    			"Url": "Myasdwfaesite.se",
    			"My-Note": "aasfase",
                "Email": "[email protected]"
                "PersonNumber": "5634543",
                "postal_code": "123445",
                "given_name": "Balling",
                "Last_name": "Calling",
                "street_address": "qwertr 123",
                "city": "London",
                "country": "UK",
                "phone": "65412331",
				"Color": "Blue",
                "house_number": "321",
				"year": "2018"
            }
            
            #Profile_2 etc etc
        }
    }
and my plan is to make the json profile/objects to work concurrently through my code.

1. Use the profiles, between 0 - x
2. concurrently it with my code
3. When finished - exit

A more visual representation:
[Image: 5nwbX.png]

*What I have done so far*

I can read one JSON object at this moment with this code:

    with open('profileMulti.json', 'r', encoding='UTF-8') as json_data:
        config = json.load(json_data
)

Which gives me this output: If the first Json profile and it cant be a added another profile inside the Json else the code will not recoinze it.

An example for code that can be made out of this
    			"Url": "Myownwebsite.se",
    			"My-Note": "Helloworld",
                "Email": "[email protected]"
                "PersonNumber": "1234543",
                "postal_code": "54123",
                "given_name": "World",
                "Last_name": "Hellow",
                "street_address": "helloworld 123",
                "city": "Stockholm",
                "country": "Sweden",
                "phone": "123456789",
^ This is from my code on below.

*What I expect to happened*...

What I expect to happened or want to make it to work is that with those information inside the Json file. To take those information --> Load it into the code (Below) - Make each json object profile to work concurrently with each THREAD and when everybody is done then exit pretty much. No mix between profile 1 and other or so. Every profile run for itself and execute the same way.


**CODE**

        with open('profileMulti.json', 'r', encoding='UTF-8') as json_data:
        config = json.load(json_data)
    
    NameUrl = config["Url"]
    
    myNote = config["My-Note"]
        
    def checkoutNames(NameUrl, nameID):
    
    #Request & other codes - Removed to recude the code
    #......
    #......
        headers = {
            'Referer': '',
            'Content-Type': ''
        }
        payload = {
            "shared": {
                "challenge": {
                    "email": config["Email"],
                    "PersonNumber": config["PersonNumber"],
                    "postal_code": config["ZipCode"],
                      "given_name": config["Name"],
                    "Last_name": config["LastName"],
                    
                    "street_address": config["Address"],
                    "postal_code": config["ZipCode"],
                    "city": config["City"],
                    "country": config["Country"],
                    "email": config["Email"],
                    "phone": config["Phone"],
                }
    			
    def checkoutNotes(NamesUrl, NamesPost):
    
    #Request & other codes - Removed to recude the code
    #......
    #......
    
        headers = {
            'Accept': 'application/json, text/javascript, /; q=0.01',
            'Accept-Language': 'en-US,en;q=0.5',
            'Accept-Encoding': 'gzip, deflate, br',
            'Referer': NameUrl,
            'Connection': 'keep-alive'
        }
        payloadInfo = {
            "Information": {
                "Color": config["Color"],
                "house_number": config["houseNumber"],
                "year": config["Year"]
          }
        }    
    def wipe():
        os.system('cls' if os.name == 'nt' else 'clear')
        
    def main():
        time.sleep(1)
       
        FindName(myNote)
    
    if _name_ == '_main_':
        try: {
            main()
        }
        except KeyboardInterrupt:
            wipe()
So easy to say. There is functions in the code such as from the beginning, checkoutNames and checkoutNotes. Basically we have different profiles. Make each profile to work concurrently with each thread for itself. Execute the code by itself and add those information from Json to the code I have entered here and vioala. That's pretty much what I dream at this moment to get it to work.

So I assume we need to make them running concurrently by multiprocess for every profile to run on their own thread without iterat between other profiles?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiprocessing: Threads work well. Processes don't work. viyubu 11 1,666 Dec-03-2023, 08:50 PM
Last Post: snippsat
  hi need help to make this code work correctly atulkul1985 5 702 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 626 Oct-22-2023, 09:08 PM
Last Post: tronic72
  Why do I have to repeat items in list slices in order to make this work? Pythonica 7 1,259 May-22-2023, 10:39 PM
Last Post: ICanIBB
  Python Split json into separate json based on node value CzarR 1 5,477 Jul-08-2022, 07:55 PM
Last Post: Larz60+
  Update old Python version because of security threads SanderV 2 1,507 Jun-06-2022, 07:49 PM
Last Post: SanderV
  Make my py script work only on 1 compter tomtom 14 3,738 Feb-20-2022, 06:19 PM
Last Post: DPaul
  Cannot make 'pandas' module to work... ellie145 2 4,138 Jan-05-2021, 09:38 PM
Last Post: ellie145
  Is there anyway to make this work? dre 3 2,108 Nov-26-2020, 12:40 PM
Last Post: jefsummers
  Passing List of Objects in Command Line Python usman 7 3,092 Sep-27-2020, 03:45 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

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