Über eine Globale variable mit einem thread

Wie kann ich eine Globale variable mit thread?

Mein Python-code-Beispiel:

from threading import Thread
import time
a = 0  #global variable

def thread1(threadname):
    #read variable "a" modify by thread 2

def thread2(threadname):
    while 1:
        a += 1
        time.sleep(1)

thread1 = Thread( target=thread1, args=("Thread-1", ) )
thread2 = Thread( target=thread2, args=("Thread-2", ) )

thread1.join()
thread2.join()

Ich weiß nicht, wie man die beiden threads teilen sich eine variable.

InformationsquelleAutor Mauro Midolo | 2013-11-05
Schreibe einen Kommentar