Python Forum
Should Python 3 become multi-threaded by design?
Poll: What do you think about it?
You do not have permission to vote in this poll.
It's impossible (too complicated to implement)
0%
0 0%
It's impossible (a logic flow)
0%
0 0%
It's possible and will be implemented before 2020
25.00%
1 25.00%
It's possible but no one will bother implementing it
75.00%
3 75.00%
Total 4 vote(s) 100%
* You voted for this item. [Show Results]

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Should Python 3 become multi-threaded by design?
#1
Should Python 3 become multi-threaded by design?
To run a program, Python would create a virtual computing pull of all available cores => run every command of the program on a separate core simultaneously => add the result & the index to the mutual memory block => threads would be returning results either as they are completed or the parsed result at the end, depending on whether it's a function or not

For example, let's say we have test.py containing the following code:

my_list = ["apple", "banana", "orange", "potato"]
for i in my_list:
   print(i)

print("this will run & stored in memory before for loop is finished")
We run this file by executing this command:

python -t4 test.py
Python does the following initialization:

- available threads: 4
- assign my_list[0] to thread 0
- assign my_list[1] to thread 1
- assign my_list[2] to thread 2
- assign my_list[3] to thread 3
- [for loop] => create [mutual_memory_block_id1938574896 = {None, return_immediately=True}]
- [print outside the loop] => create [mutual_memory_block_id7788 = {None, return_immediately=True}]

Threads are running randomly & simultaneously:

thread 2:
- mutual_memory_block_id1938574896.update = [ $my_list[2]{"orange"} ]
- thread 2 => status = "Available'
- thread 2 assigned for the next job =>
- thread 2 runs the "next job" - (print outside the loop) immediately since no additional data required => stores the result => returns when ready: mutual_memory_block_id7788.update = [$print("this will run & stored in memory before for loop is finished")]

thread 0:
- mutual_memory_block_id1938574896.update = [ $my_list[0]{"apple"} , $[2]{"orange"} ]
- thread 0 => prints the [0] element on the screen since {return_immediately=True} and mutual_memory_block_id1938574896[0] is available
- thread 0 => status = "Available'

thread 1:
- mutual_memory_block_id1938574896.update = [ $my_list[0]{"apple"}, $my_list[1]{"banana"}, $my_list[2]{"orange"} ]
- thread 1 => prints the [1] element on the screen since {return_immediately=True} and mutual_memory_block_id1938574896[1] is available
- thread 1 => prints the [2] element on the screen since {return_immediately=True} and mutual_memory_block_id1938574896[2] is available
- thread 1 => status = "Available'

thread 3:
- mutual_memory_block_id1938574896.update = [ $my_list[0]{"apple"}, $my_list[1]{"banana"}, $my_list[2]{"orange"}, $my_list[3]{"potato"} ]
- thread 3 => prints the [3] element on the screen since {return_immediately=True} and mutual_memory_block_id1938574896[3] is available
- thread 3 => status = "Available'

####### for loop is done ########

Meanwhile, in the background - thread 1 (is the first available after thread 0)
- are we there yet? {no}, are we there yet? {no}, are we there yet? {no}, are we there yet? {no} ....
- are we there yet? {YES!},
- get from memory mutual_memory_block_id7788
- output it

####### print outside the loop is done ########

P.S.
if the loop would be inside a function, then the loop, during initialization, would get {return_immediately=False}
1. threads wouldn't return their data immediately and would check if the loop is done & function is ready to return the output
2. the first available thread would be gathering the return values and compile it in memory, adding the new bits of data from other cores, and in the end it would get the value from memory and output it at once, like:
- get from memory mutual_memory_block_id1938574896 = [ $my_list[0]{"apple"}, $my_list[1]{"banana"}, $my_list[2]{"orange"}, $my_list[3]{"potato"} ]
- output it


I'm just a beginner in programming and I'm creating this logic as I write this post, if it's flawed, please don't be too angry with my ignorance, give some useful feedback on why it's a flawed idea, instead. I don't have enough knowledge to implement it myself, so just wanted to share this quick idea with the community and discuss if it's even possible.
Reply


Messages In This Thread
Should Python 3 become multi-threaded by design? - by uc1 - Jul-22-2017, 05:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  High level Python program architectural design question - decoration for multiple ent yahbai 0 1,846 Jan-16-2020, 08:30 PM
Last Post: yahbai
  Design pattern in python Prabakaran141 3 3,134 Nov-20-2018, 01:45 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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