Implementing concurrent programming under the CPython interpreter

Source: Internet
Author: User
Tags key string

Read Catalogue

    • A background knowledge
    • Multi-process of two Python concurrent programming
    • Multi-Threading with three Python concurrent programming
    • The Association of four Python concurrent programming
    • IO model of five Python concurrent programming
    • Six additions: Paramiko module
    • Seven jobs
A background knowledge

As the name implies, a process is a process that is being executed. A process is an abstraction of a running program.

The concept of process originates from the operating system, is the core concept of the operating system, and is one of the oldest and most important abstract concepts provided by the operating system. Everything else in the operating system is expanded around the concept of processes.

So to really understand the process, you must know the operating system beforehand, click Enter

PS: The ability to support (pseudo) concurrency can be guaranteed even if there is only one CPU available (this is true for earlier computers). Turning a single CPU into multiple virtual CPUs (multi-channel technology: Time multiplexing and spatial multiplexing + hardware support isolation), without process abstraction, modern computers will no longer exist.

The necessary theoretical basis:

# the role of an operating system:    1: Hide ugly complex hardware interfaces, provide good abstraction    interface 2: Manage, schedule processes, and compete for hardware with multiple processes # two multi-channel technology:    1  Background: For the single core, to achieve concurrent    PS:    Now the host is generally multicore, then each core will use multi-channel technology    has 4 CPUs, a program running in CPU1 encountered IO blocking, will wait until the end of IO and re-Dispatch, will be dispatched to 4    any one of the CPUs, which is determined by the operating system scheduling algorithm.         2. Reuse in space: if there are multiple programs    in memory 3. Time reuse: Multiplexing a CPU time slice       emphasis: Encountering IO cut, taking up CPU time too long also cut, The core is to save the state of the process before it is cut, so that the            next time you switch back, you can continue to run based on where you last cut off.

This article focuses on the process and its relatives--threads

Multi-process of two Python concurrent programming

Theory: http://www.cnblogs.com/llhtjwq/p/8306621.html

Links: http://www.cnblogs.com/llhtjwq/p/8306636.html

Multi-Threading with three Python concurrent programming

Theory: http://www.cnblogs.com/llhtjwq/p/8306642.html

Links: http://www.cnblogs.com/llhtjwq/p/8306659.html

The Association of four Python concurrent programming

Links: http://www.cnblogs.com/llhtjwq/p/8306665.html

IO model of five Python concurrent programming

Links: http://www.cnblogs.com/llhtjwq/p/8306677.html

Six additions: Paramiko module

1. Introduction:

Paramiko is a module for remote control, which can be used to command or file the remote server, it is worth saying that the fabric and ansible internal remote management is the use of Paramiko to reality.

2. Download and install

PIP3 Install Paramiko #在python3中
in the Python2

3. Use

Sshclient

Used to connect to a remote server and execute basic commands

Connect based on user name password:

ImportParamiko#To create an SSH objectSSH =Paramiko. Sshclient ()#allow connections to hosts that are not in the Know_hosts fileSsh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())#connecting to a serverSsh.connect (hostname='120.92.84.249', Port=22, Username='Root', password='XXX')#Execute Commandstdin, stdout, stderr = Ssh.exec_command ('DF')#Get command Resultsresult =Stdout.read ()Print(Result.decode ('Utf-8'))#Close ConnectionSsh.close ()
sshclient Package Transport

Connection based on public key:

Client file name: I D_rsa

The server must have a file name: Authorized_keys (when using Ssh-keygen, must make a authorized_keys, can be made with Ssh-copy-id)

View Codesshclient Package TransportConnect based on a private key string

Sftpclient

For connecting to a remote server and performing an upload download

Upload and download based on user name password

View Code

Upload and download based on public key keys

View CodeDemo Seven jobs

Title: Simple Mainframe Bulk management tool

Demand:

    1. Host grouping
    2. Host information configuration file with Configparser parsing
    3. Can execute the command in batch, send the file, the result returns in real time, the execution format is as follows
      1. Batch_run-h h1,h2,h3-g web_clusters,db_servers-cmd "Df-h"
      2. Batch_scp-h h1,h2,h3-g web_clusters,db_servers-action put-local test.py-remote/tmp/
    4. Host user name password, port can be different
    5. Execute remote command using Paramiko module
    6. Bulk commands need to use multiprocessing concurrency

Implementing concurrent programming under the CPython interpreter

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.