ETExamTower
Q43Software Development and Design

Refer to the exhibit. Python threading lets a developer run separate parts of a program concurrently and can simplify a design. Drag the code snippets to the numbered items that complete the exhibit and create a thread instance. <DragDrop items={["join()","threading.Thread","start()","target","args"]} slots={[{"answer":"threading.Thread","id":"item1"},{"answer":"target","id":"item2"},{"answer":"args","id":"item3"},{"answer":"start()","id":"item4"},{"answer":"join()","id":"item5"}]} template={"import threading\nimport requests\n\ndef get_device_list(endpoint, apikey):\n url = \"https://api.meraki.com/api/v0/networks/\" + endpoint\n hdr = {'x-cisco-meraki-api-key': format(str(apikey)), 'Content-Type':\n'application/json'}\n response = requests.get(url=url, headers=hdr)\n print(response.json())\n\nif __name__ == \"__main__\":\n # creating thread\n thread = {{item1}}({{item2}}=get_device_list,\n {{item3}}=(\"NETWORK_ID/devices\",\"API_TOKEN\"))\n\n thread.{{item4}}\n thread.{{item5}}"} explanation={"`threading.Thread` creates the thread object. Its `target` parameter identifies the function to run, and `args` supplies that function’s positional arguments. Calling `start()` begins execution in the new thread, while `join()` waits for that thread to finish."} reuse={false} />

Question exhibit
← → navigate · a answer
Discussion · 3
14
I agree with FR99. 1. threading.Thread 2. target 3. args 4. start() 5. join() Explanation: Threading in python is used to run multiple threads (tasks, function calls) at the same time. Note that this does not mean they are executed on different CPUs. Python threads are used in cases where a task has to wait for something. One example would be interaction with a service hosted on another computer, such as a webserver. Threading lets python execute other code while it is waiting; this is easy to simulate with the sleep function. import time import threading def myfunc(name): print(f'myfunc started with {name}') time.sleep(10) print('myfunc ended') if __name__ == '__main__': print('main started') thread = threading.Thread(target=myfunc,args=['realpython']) thread.start() print('main ended') https://realpython.com/lessons/two-threads/
7
I agree that the answer is: 1. threading.Thread 2. target 3. args 4. start() 5. join()
3
For anyone wondering what join() does (as i did): https://stackoverflow.com/questions/15085348/what-is-the-use-of-join-in-threading This also shows where join() should be placed (after the start()).