Outils pour utilisateurs

Outils du site


tech:notes_python_multithreading

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
tech:notes_python_multithreading [2025/04/26 11:13] Jean-Baptistetech:notes_python_multithreading [2025/05/20 17:51] (Version actuelle) Jean-Baptiste
Ligne 12: Ligne 12:
 * https://pypi.org/project/pygolang/ * https://pypi.org/project/pygolang/
 * https://pypi.org/project/python-defer/ * https://pypi.org/project/python-defer/
 +
 +
 +Thread safe :
 +* https://plainenglish.io/blog/thread-safety-in-python
 +* https://jonbleiberg.medium.com/how-python-keeps-your-queues-thread-safe-4b66a2f3e692
 +
 +
  
 Nombre de CPU logiques Nombre de CPU logiques
Ligne 294: Ligne 301:
 </code> </code>
 Source : https://stackoverflow.com/questions/56318648/how-to-run-an-asyncio-task-without-awaiting Source : https://stackoverflow.com/questions/56318648/how-to-run-an-asyncio-task-without-awaiting
 +
 +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()
 +</code>
 +
 +
 +Source : https://www.cloudthat.com/resources/blog/writing-thread-safe-programs-in-python
 +
 +---------
 +
 +Source : nsclient ''NSCP-0.8.0-x64/scripts/python''
 +
 +''badapp.py''
 +<code python>
 +#! /usr/bin/env python3
 +
 +import threading
 +
 +class BadThread(threading.Thread):
 +        id = -1
 +        def __init__(self, id):
 +                self.id = id
 +                threading.Thread.__init__(self)
 +
 +        def run(self):
 +                i = 0
 +                while(True):
 +                        i = i + 1
 +                        if i > 100000:
 +                                print('Processing: %d'%self.id)
 +                                i = 0
 +
 +for x in range(1000):
 +        BadThread(x).start()
 +</code>
  
  
tech/notes_python_multithreading.1745658818.txt.gz · Dernière modification : de Jean-Baptiste

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki