The most basic form of something I want to code is the code as follows:
import threading
arr = []
def test(id):
global arr
arr.append(id)
threading.Thread(target=test, args="8")
print(arr)
What I want to do is to append "8" to a global variable called arr But this doesn't happen, and print(arr) gives this output:
[]
However, if I use this code, everything works fine:
import threading
arr = []
def test(id):
global arr
arr.append(id)
test("8")
print(arr)
The problem seems to be with thread, so how can I use thread and also change the value of a global variable inside the function test?