Destructors, Private, class methods; inheritance; environment deployment; multi-threaded, multi-process; locks

Source: Internet
Author: User
Tags instance method

1. Destructors, Private, class methods, property methods, static methods
Class My:
def __init__ (self):
Print (' constructor, class will automatically execute when instantiated. ')
def __del__ (self): #析构函数, this instance is automatically executed when it is destroyed.
Self.__client.close ()
Def say (self): #实例方法
Print (' I'm milk ')
__cry () can call to Private function __cry () when calling the Say method outside the class
def __cry (self):
#函数名或者变量名前面加__, this function or variable is private, private can only be used inside the class, private more secure, out of class, the contents of the method can not be modified
Print (' Whoa Wah ')
M=my ()
If there is no code after this line of code, representing the instance being deleted in memory, the destructor will be executed automatically
If there is another code behind this line of code that does not destroy the instance manually, then the destructor is automatically executed when the other code finishes executing
If there is a del m behind this line of code, destroy the instance manually, and then there are other code down, then execute the other code after the destructor is executed

@classmethod #类方法, without instantiation, can be called directly; adorners, do not change the original function, add new functions to the function
Def eat (CLS):
Print (' Eat ')
@staticmethod #静态方法
def run ():
Pass
@property #属性方法
def red_pag (self):
Return 100
# class Method:
# 1. Do not instantiate, call directly with the class name for example: My.eat ()

# 2. He can use class variables, cls.xxx, where the CLS represents my
# 3. Instantiation can also be used directly through self.xx to use the class method
# 4. Class method inside it is not available with these instance methods and instance variables that are self.xxxx

# static Method:
# is a normal function, which is defined in the class.
# No instance method, no instance variable, no class method, no class variable
# There is no need to instantiate, just call the class name

# Property Method:
# looks like a function of a method
# instance method
# He can't have an entry
# Use it, direct m.func, take him as a variable is OK, do not need parentheses to call
# He's the return value of the Get function

2. Inheritance
#目的是为了减少代码, reduce duplicate code
Class Ln:  #父类
Money= ' 2000 '
def Make_money (self):
Print (' Earn money ')

Class Me (Ln): #子类
Pass
Print (Me.money) #继承父类 with a result of 2000
Nhy=me ()
Nhy.make_money ()
If the method in the subclass is refactored, the refactoring method is the
If you modify the method of the parent class on the basis of the parent class method, you can call the parent class's corresponding method in the subclass method, namely: the parent class. Method Name (self,**,**) All parameters of the method in parentheses, and self must be passed

3. Environment deployment

How to build a test environment
First time Building
1. Install dependent software MySQL, Redis, Tomcat, Nginx, JDK
database, middleware, etc.
2. Get the code svn git
3. Compiling (Java C c##)
4. Import basic Data
5. Modify the configuration file
6. Start the project

Daily deployment
1. Get the latest code
2. Compiling (Java C c##)
3. Execute SQL (if the database changes)
4. Modify the configuration file
5. Restart the project

4. Multithreading, multi-process
# process: A process is a program
# Thread: A thread is the smallest execution unit within a process
# threads are on the inside, working or threading
# one in which there is at least one thread that can have multiple threads
# Each thread is independent of each other
# no real concurrency, the computer is a few cores, so you can run a few tasks at the same time

# Python inside Multi-threading, is not using multi-core CPU, can only take advantage of a core CPU
# In some cases, when you use multithreading, you find that it is slower than a single thread
# Gil Global Interpreter lock
# 1. Why Python multithreading isn't using multicore CPUs, but it's still faster than a single thread

# When to use multithreading, when to use multi-process?
# Multithreading for IO-intensive tasks
# Disk IO
# Network IO

# Multi-process for CPU-intensive tasks
# Multi-process, is a multi-core CPU can be used

Destructors, Private, class methods; inheritance; environment deployment; multi-threaded, multi-process; locks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.