python:async

Ceci est une ancienne révision du document !


Programmation asynchrone

from threading import Thread
 
class RunFuncAsync(Thread):
    def __init__(self, func, args):
        Thread.__init__(self)
	self.func = func
	self.args = args
 
    def run(self):
	self.func(self.args)
 
threads = []
 
for _ in range(nb_of_threads):
    threads.append(RunFuncAsync(func, args))
 
for t in threads:
    t.start()
 
for t in threads:
    t.join()
from threading import RLock
 
verrou = RLock()
 
class ThreadClass(Thread):
    def run(self):
        with verrou:
            # section critique
  • python/async.1544006419.txt.gz
  • Dernière modification : 2021/04/04 17:01
  • (modification externe)