Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multithreading
#2
For function arguments, the order always positional args, keyword args, and keyword-only args. The reason for this is that keyword arguments can be assigned as position arguments.

def test(var1=0, var2=0):
	return var1 + var2

test(4, 5) # Returns 9
In order to do that, the order of the keyword arguments must be maintained as long as positional arguments are provided. If we were to do test(var2=3, 4), the interpreter would be attempting to assign var2 twice which means that var1 isn't assigned. In this case, that wouldn't be the end of the world since var1 has a default value, but if it were a positional argument, that would be a problem.

The Thread.join() method runs a loop that repeatedly checks the status of the active Thread object. If the Thread is still alive - meaning that its Thread.run() has not returned - then the loop continues. It does two primary things:

  1. By halting execution of the main thread, it prevents code which may be dependent on the tasks in the thread from running. If such code were to run, it would encounter errors.
  2. It also prevents the main thread from completing. If the main thread were to complete, the program would exit. The Threads would still be running as zombies in the because they are independent of the main thread. Halting the main thread enables you to get feedback on the status of the other Threads.
Reply


Messages In This Thread
Multithreading - by Truman - Feb-10-2019, 01:55 AM
RE: Multithreading - by stullis - Feb-10-2019, 02:57 AM
RE: Multithreading - by scidam - Feb-10-2019, 04:42 AM
RE: Multithreading - by Truman - Feb-11-2019, 01:44 AM
RE: Multithreading - by stullis - Feb-11-2019, 04:32 AM
RE: Multithreading - by Truman - Feb-12-2019, 01:22 AM

Forum Jump:

User Panel Messages

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