Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the common method of Python threading module

Shulou Source: shulou.com Published: 2022-05-31 17:49:17 11月13日 Update

This article introduces the knowledge of "what are the common methods of Python threading module". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Description

1. Threading.curentthread (): returns the current thread variable.

2. Threading.enumerate (): returns the list containing the running thread. Post-startup and pre-end threads that do not include pre-start and post-end threads.

Threading.activeCount (): has the same result as len (threading.enumerate ()).

Example

"" Common methods of python threading modules "" import timeimport threading def test1 (): print ('- test1-') time.sleep (3) def test2 (): print ('- test2-') time.sleep (3) def main (): T1 = threading.Thread (target=test1) T2 = threading.Thread (target=test2) t1.start () T2.start () print ('activeCount:% d'% threading.activeCount ()) print (threading.enumerate ()) while threading.activeCount ()! = 1: time.sleep (1) print (threading.enumerate ()) print (threading.enumerate ()) if _ _ name__ = =' _ main__': main () what are the common methods of Python threading modules? Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Threads commonly used methods modules content more knowledge practical same successful learning next variables dilemmas instances actual situation articles cases ongoing results Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Huawei Apple MySQL NVidia