tech:notes_python_multithreading
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| tech:notes_python_multithreading [2025/03/24 15:06] – créée - modification externe 127.0.0.1 | tech:notes_python_multithreading [2025/05/20 17:51] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 12: | Ligne 12: | ||
| * https:// | * https:// | ||
| * https:// | * https:// | ||
| + | |||
| + | |||
| + | Thread safe : | ||
| + | * https:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| Nombre de CPU logiques | Nombre de CPU logiques | ||
| Ligne 195: | Ligne 202: | ||
| * Vous pouvez uniquement utiliser '' | * Vous pouvez uniquement utiliser '' | ||
| * Une Coroutune déclarée avec '' | * Une Coroutune déclarée avec '' | ||
| - | ** '' | + | |
| - | ** '' | + | * '' |
| - | ** '' | + | * '' |
| - | ** '' | + | * '' |
| * " | * " | ||
| * '' | * '' | ||
| Ligne 294: | Ligne 301: | ||
| </ | </ | ||
| Source : https:// | Source : https:// | ||
| + | |||
| + | Thread safe | ||
| + | |||
| + | <code python> | ||
| + | from collections import deque | ||
| + | |||
| + | thread_safe_deque = deque() | ||
| + | |||
| + | # Thread 1 | ||
| + | thread_safe_deque.append(1) | ||
| + | |||
| + | # Thread 2 | ||
| + | element = thread_safe_deque.pop() | ||
| + | </ | ||
| + | |||
| + | |||
| + | Source : https:// | ||
| + | |||
| + | --------- | ||
| + | |||
| + | Source : nsclient '' | ||
| + | |||
| + | '' | ||
| + | <code python> | ||
| + | #! / | ||
| + | |||
| + | import threading | ||
| + | |||
| + | class BadThread(threading.Thread): | ||
| + | id = -1 | ||
| + | def __init__(self, | ||
| + | self.id = id | ||
| + | threading.Thread.__init__(self) | ||
| + | |||
| + | def run(self): | ||
| + | i = 0 | ||
| + | while(True): | ||
| + | i = i + 1 | ||
| + | if i > 100000: | ||
| + | print(' | ||
| + | i = 0 | ||
| + | |||
| + | for x in range(1000): | ||
| + | BadThread(x).start() | ||
| + | </ | ||
tech/notes_python_multithreading.1742825205.txt.gz · Dernière modification : de 127.0.0.1
