Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Python Multithreaded Programming     - Linux environment to build next Cocos2dx-3.3.1 (Linux)

- Java memory area Explanation (Programming)

- Novice Advanced Ubuntu7.10 configured IP address (Linux)

- CentOS7 install JDK (Linux)

- Android realize RippleEffect water (Programming)

- Explore Android SQLite3 multithreading (Programming)

- Easily solve the MySQL database connection error too many (Database)

- Some MySQL interview questions (Database)

- Detailed usage history command (Linux)

- Linux System Getting Started Tutorial: Linux file permissions brief description (Linux)

- S5PV210 development board for embedded development environment to build under Ubuntu (Linux)

- Kubernetes resolve application deployment model (Server)

- Ordinary users how the Linux system shutdown (Linux)

- Git commands (Linux)

- CentOS / Linux NIC set IP address configuration (Linux)

- CentOS set up FTP server (Server)

- Programmer editor Vim (Linux)

- Windows 7 hard disk installation notes Debian (Linux)

- Linux Thread Synchronization (Programming)

- Python 3.5 await / async (Programming)

 
         
  Python Multithreaded Programming
     
  Add Date : 2017-04-13      
         
         
         
  Python2.4 ago a thread module supports multi-threaded programming, after 2.4 adds threading module provides a higher level and more powerful thread support.

threading.activeCount (): Returns the number of active thread object
threading.currentThread (): Returns the object for the current thread of execution cpu
threading.enumerate (): Returns a list of the currently active thread object
In addition, threading and provides a lot of java in the Thread class in the same way :( Note that this is both an instance method)

run (): The run () method is the entry point for a thread.
start (): The start () method starts a thread by calling the run method.
join ([time]): The join () waits for threads to terminate.
isAlive (): The isAlive () method checks whether a thread is still executing.
getName (): The getName () method returns the name of a thread.
setName (): The setName () method sets the name of a thread.
There are two ways to create threads:

1) Inheritance threading.Thread

a. Create a subclass threading.Thread
b. covering init (self [, args])
c. Rewrite run method

#! / Usr / bin / python
#! Coding = utf-8
import threading
import time
exitFlag = 0
class MyThread (threading.Thread):
    def __init __ (self, threadID, name, counter):
        threading.Thread .__ init __ (self)
        self.threadID = threadID
        self.name = name
        self.counter = counter

    def run (self):
        task ()

    def task (self):
       '' 'Thread to perform the task' ''
       print 'starting' + self.name
       print 'exiting' + self.name

# Create a thread
thread1 = MyThread (1, 'Thread-1', 1)
thread2 = MyThread (2, 'Thread-2', 2)

# Start a thread
thread1.start ()
thread2.start ()

# End waiting thread
thread1.join ()
thread2.join ()

print 'exiting main thread'
2) task function passed as a parameter to the method Thread

threading.Thread (target = task, args = ()). start ()
     
         
         
         
  More:      
 
- Use the TC flow control test under Linux (Linux)
- Install VMware Tools in Debian (Linux)
- Detailed use Zabbix monitoring Nginx (Server)
- libreadline.so.6: can not open shared object file problem solution (Linux)
- Production environment Linux bonding method standby mode slave card switch (Server)
- Linux install Maven and SVN client (Linux)
- Use read command to read user input (Programming)
- Bash common several configuration files (Linux)
- Install Ruby on Rails in Ubuntu 15.04 in (Linux)
- echo command (Linux)
- Linux loopback adapter Driven Design (Programming)
- MongoDB3.0.x version of the user authorization profile (stand-alone environment) (Database)
- Running into the site-wide HTTPS (Server)
- CentOS7 method to upgrade the kernel to 3.18 (Linux)
- Mutt - an email client that sends messages through the terminal (Linux)
- Hackers is how the invasion and control of Things devices? (Linux)
- Install Redis 2.6 5.5 32 position CentOS error resolved (Linux)
- Linux and Windows Security Topics (Linux)
- CentOS 6.5 / 6.6 modify the default SSH port number (Linux)
- Linux more command Detailed (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.