Python creates thread implementations using object-oriented methods 12306 ticketing system

Source: Internet
Author: User
At present, Python provides several ways to implement multi-threading thread,threading,multithreading, where the thread module compared to the bottom, and the threading module is the thread to do some packaging, can be more convenient to be used.

Introduction to Object-oriented technology

Class: Used to describe a collection of objects that have the same properties and methods. It defines the properties and methods that are common to each object in the collection. An object is an instance of a class.

Class variables: class variables are common throughout the instantiated object. Class variables are defined in the class and outside the body of the function. Class variables are not typically used as instance variables.

data members: class variables or instance variables are used to manipulate the data related to the class and its instance objects.

method Overrides: if the method inherited from the parent class does not meet the requirements of the subclass, it can be overridden, which is called the override of the method, also known as the override of the method.

instance variable: A variable defined in a method that acts only on the class of the current instance.

inheritance: A derived class (derived class) that inherits the fields and methods of the base class. Inheritance also allows the object of a derived class to be treated as a base class object. For example, there is a design where an object of type dog is derived from the animal class, which is the analog "is a (is-a)" Relationship (example, dog is a animal).

instantiation: Creates an instance of a class, the concrete object of the class.

method: a function defined in a class.

object: An instance of a data structure defined by a class. The object consists of two data members (class variables and instance variables) and methods.

---restore content starts---

Multi-Threading is implemented through an object-oriented approach, with the core of inheriting threading. Thread class. We define a class booththread ourselves, which inherits from thread. The threading class defines the command to be executed by a thread by modifying the run () method of the thread class.

A dictionary monitor is used to store the global variables, and the dictionary is passed as a parameter to the thread function. Since the dictionary is a mutable data object, when it is passed to the function, the function is still using the same object, which is equivalent to being shared by multiple threads.

This article describes python using object-oriented approach to create a thread implementation of the 12306 ticketing system of all the narrative, I hope you like.

  • Related Article

    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.