Japanese badminton beauty group rises fast, Beijing Olympic Games competes for medals (Figure)

  


  Since last year, Japanese women’s doubles have sprung up, and soon replaced South Korean Lee Kyung won/Lee Hyo jung as a new force to compete with the powerful China women’s doubles. Even Tian Bingyi, head coach of China women’s doubles, said: Japanese women’s doubles have made rapid progress in recent years, and their impact on us has surpassed that of the Korean team to some extent.


  At present, the Japanese team has three pairs of strong women’s doubles, among which Reiko Shiota/Kumiko Ogura, who is called a beauty group by many media, has the best record and can be called the first women’s doubles in Japan today.


  Childhood opponent, today’s partner


  Reiko Shiota and Kumiko Ogura started practicing badminton just by learning to play. After practicing badminton, they have different joys and sorrows. On September 30th, 1983, Reiko Shiota was born in Fukuoka Prefecture. In the first grade of primary school, at the invitation of her friends, she entered Kyoto Club, a famous badminton school in Japan, and began to practice badminton. Reiko Shiota, who was just going to have fun at first, underwent "devil training" at school. She not only had to practice basic skills, but also ran marathons. It was common for her to be beaten for being lazy. In her memory, she never felt that playing badminton was a happy thing.


  On July 5, 1983, Kumiko Ogura was born in Mie Prefecture. At the age of 8, influenced by her sister, she began to practice badminton. Like Reiko Shiota, Kumiko Ogura just started playing and just learned to play. But unlike her future partner, playing ball is a kind of enjoyment for Kumiko Ogura. She likes to fight for every point and doesn’t like to have a rest.


  In the sixth grade, Reiko Shiota and Kumiko Ogura met for the first time. Reiko Shiota beat Kumiko Ogura in the women’s singles quarter-final of the Japanese national primary school competition. Now, Reiko Shiota has no impression of the game, but Kumiko Ogura has a deep memory. She said that it was very good to play in Chaotian at that time, not like a primary school student at all. In the second grade of junior high school, the two met again in the women’s singles semi-final of the Japanese youth competition, and Reiko Shiota won again.


  Two years later, the two men who entered high school were first put together in a youth training camp in Japan. At the beginning of the cooperation, they felt very tacit understanding, which was nothing like the first cooperation. Later, they were arranged to train with older players. Reiko Shiota said: "When I first cooperated with Xiao Yun, I was not very interested in doubles, but it was a pleasure to beat the older players in the competition." After graduating from high school, Reiko Shiota and Kumiko Ogura joined Sanyo Electric Company and started working and training together.


  Stiffness and softness complement each other.


  Looking at the game between Reiko Shiota and Kumiko Ogura, we can find that their styles are very different-Reiko Shiota is gentle when hitting the ball, but Kumiko Ogura is powerful; Reiko Shiota likes to observe his opponents in the game and plays strategically. Kumiko Ogura prefers to confront his opponent directly.


  On the field, Reiko Shiota is a careful person. She always leads Kumiko Ogura like a commander and creates opportunities for her to attack. Off the court, Reiko Shiota is like a careless sister. Every training session, Kumiko Ogura will gather 10 minutes in advance, while Reiko Shiota is not so punctual. When staying in a hotel for a competition abroad, Kumiko Ogura always gets up early and is responsible for waking Reiko Shiota up. The key to the door is also kept by a careful little coffin.


  Reiko Shiota feels that her psychological quality still needs to be strong. She hopes to participate in more competitions and accumulate experience, so as to build her confidence. Kumiko Ogura is always confident, and her spike speed reaches 260 km/h, making her a rare heavy gunner in the Japanese women’s team. Kumiko Ogura likes to entertain foolish ideas at ordinary times, so Reiko Shiota encourages her not to be influenced by others, and to have her own opinions. After they joined Sanyo Electric Company in 2002, they were strongly trained by China’s coach Ding Qiqing, and their level rose rapidly.


  Their different personalities make them form a good complement on and off the court, and they gradually become the best women’s doubles players in Japan. In 2004, Reiko Shiota/Kumiko Ogura won the Japanese women’s doubles championship for the first time, and qualified for the Athens Olympic Games. Unfortunately, because Kumiko Ogura broke his left little finger before the Olympic Games, they failed to board the flight to Athens.


  Athens regrets Beijing’s bid for medals


  When Kumiko Ogura participated in the national competition in the sixth grade, her parents joked that "you can go to the Olympic Games in the future". After she really qualified for the Olympic Games but lost the opportunity, Xiao Yun was very disappointed. She recalled: "It was really frustrating to quit the competition because of injury. After that, I made up my mind to challenge the Beijing Olympic Games four years later. " Reiko Shiota said, "When I was a child, I never thought about the Olympic Games at all, and I didn’t think I had the talent to be an athlete. It was not until Xiao Yun invited me to join Sanyo Electric Company that we began to participate in the Olympic points competition and saw the possibility of participating in the Olympic Games. I want to thank Xiao Yun. Without her, I can’t go to the Olympic Games alone. "


  At the 2004 Athens Olympic Games, Reiko Shiota and Kumiko Ogura were spectators sitting in front of the TV. Kumiko Ogura secretly vowed that she would stand on the Olympic stage one day after seeing "Miss Judo" Gu Liangzi win the first gold medal in Athens Olympic Games for the Japanese team.


  Since 2005, Reiko Shiota and Kumiko Ogura have stood out in international competitions, and they have spread their dream wings to fly towards the Beijing Olympic Games. In the 2005 Danish Open, they defeated China’s Zhang Yawen/Zhang Dan and England’s Ames/Clogg successively, and won the women’s doubles gold medal in this five-star international competition for the Japanese team.


  In the 2006 Asian Games in Doha, Reiko Shiota/Kumiko Ogura met China’s Yang Wei/Bonita in the semi-final, and they lost to their opponents after three sets of bitter battles. Despite losing to Yang Wei/Bonita in succession, Reiko Shiota/Kumiko Ogura is making progress. By playing against the players from China, they found out the ball path of Yang Wei/Bonita and improved their confrontation ability. In 2007, they met Yang Wei/Bonita for the sixth time in the quarterfinals of Malaysian Super Tournament, and defeated their opponents for the first time, resulting in a big upset.


  At the World Championships in August this year, Kumiko Ogura and Reiko Shiota were ranked as the sixth seeds, and they will make it to the semi-finals. In the semi-final, Kumiko Ogura and Reiko Shiota took advantage of the disadvantage of both Gao Kun and Huang Sui, and created a lot of trouble for Gao Kun/.Although they lost the game, they still created their best record in the World Championships.


  Now, Reiko Shiota/Kumiko Ogura, whose record and appearance are equally outstanding, not only appear in badminton teaching programs of major Japanese TV stations, but also serve as beverage spokespersons, publish photo albums and appear in movies, and even coach Ding Qiqing laments their high popularity. Ding Qiqing said that Reiko Shiota/Kumiko Ogura had a relaxed mentality when they played. They trained five days a week, working in the morning and training in the afternoon. Although there is a big gap with China’s athletes in strength and speed, they still set the goal of winning medals in the Beijing Olympic Games. At present, Reiko Shiota/Kumiko Ogura’s primary goal is to do a good job in the Olympic points competition, enter the top 16 in the world, and ensure the qualification for the Olympic Games.


  One year before the Beijing Olympic Games, Reiko Shiota/Kumiko Ogura expressed his earnest expectation for the Olympic Games next year in an interview with the Japanese newspaper Asahi Shimbun. Reiko Shiota said: "The Olympic Games four years ago was still a vague dream for me. Now, it is not only a goal, but also something I must accomplish." Kumiko Ogura, on the other hand, said that we must turn the regrets four years ago into the driving force for progress. They believe that they will have a day in dreams may come at the 2008 Olympic Games.

Editor: Shuo Yang

Stick to exercise, what changes will happen to your body? Understand in one article ↓

Insisting on exercise is good for physical and mental health. Many friends, because of hard exercise, have healthy bodies. There are still some friends who are unable to act for various reasons. After all, exercise is really: too tired!

What are the benefits of insisting on exercise? Today, we will give you a wave of chicken blood.

01

"I have been running for 5 years, from more than 160 kilograms to 120 kilograms. My high blood pressure, moderate fatty liver and overweight have long since disappeared."

analysis

Exercise is one of the most active and effective methods to prevent obesity, which can not only help control weight and improve physiological function, but also prevent weight rebound and reduce the occurrence of chronic diseases related to obesity.

In addition, adhering to regular exercise can also improve heart function and vascular elasticity, lower blood pressure, reduce inflammatory factors, regulate blood lipids, reduce cardiovascular risk factors, effectively prevent cardiovascular diseases and promote the rehabilitation of cardiovascular patients.

02

"The biggest feeling that insisting on exercise gives me is that I feel energetic every day and my life and work become very relaxed."

analysis

Regular exercise is good for brain health, which can not only cause good emotional and state reactions, but also reduce the release of inhibitory neurotransmitters and delay central fatigue, thus making life more enjoyable and work easier.

03

"After running for three months, the body fat dropped from 30% to 17%. Now you can clearly see the abdominal muscles, and people are much lighter. I will continue to refuel and strive to make myself stronger and healthier. "

analysis

Aerobic exercise belongs to the exercise in which the amount of oxygen consumed and the amount of oxygen absorbed are equal. Long-term and moderate-intensity exercise can increase body fat consumption and is an ideal way to reduce fat.

Three simple steps to master moderate-intensity aerobic exercise easily:

1. Calculate the maximum heart rate: maximum heart rate =205.8- age x0.685.

2. Calculate the moderate intensity exercise heart rate: moderate intensity exercise heart rate =64%~76%* maximum heart rate.

3. Bring heart rate monitoring equipment to control the exercise heart rate in a moderate intensity range.

04

"After exercising, I have a good sleep and can go into deep sleep."

analysis

Exercise can make the brain secrete endorphins, improve the individual’s pleasant experience, release the inner anxiety and pressure, and thus improve sleep. Moderate exercise fatigue can also shorten sleep time, deepen sleep depth and improve sleep quality.

Exercise is helpful to sleep, but strenuous exercise should be avoided 3 to 4 hours before going to bed, otherwise it is likely to have the opposite effect.

These are just the tip of the iceberg. Can you still sit still after reading it?

(Popular Science China)

Exploring culture: What is culture and how to identify whether there is culture or not?

Culture refers to the values, belief system, behavior norms, artistic creation, language, customs and traditions shared by a society or group. It is the product of human evolution and social development, which helps to shape the identity and thinking mode of individuals and groups.

Identifying whether a person has a culture is not simply about whether he has a high degree of education or extensive knowledge. The embodiment of culture depends more on a person’s ideological depth, values, interpersonal communication and behavior. Here are some ways to identify whether a person is literate or not:

Breadth and depth of knowledge: A literate person usually has a wide range of knowledge, not limited to a certain field, but also can deeply understand and think about what he has learned.

Open mind and curiosity: Educated people usually have open mind, are willing to accept new ideas and ideas, and are curious about different cultures and concepts.

Art and aesthetic consciousness: Culture and art are closely related, and literate people usually have a certain ability to appreciate and understand art forms such as painting, music and literature.

Language expression ability: A literate person usually has good language expression ability and can express his views and thoughts in accurate and vivid language.

Social consciousness and code of conduct: Educated people usually have high social consciousness, can respect others, abide by social code of conduct, and actively participate in social activities.

In a word, literacy is not only knowledge, but also a way of thinking, a code of conduct and an understanding of the world. By observing a person’s knowledge, way of thinking, artistic appreciation, language expression and social behavior, we can preliminarily judge whether he has culture or not. However, culture is a complex concept, and everyone’s understanding and expression may be different, so we should keep an open mind, respect diversity, and have positive exchanges and dialogues with others.

Digital Economy Empowering and High-quality Development The 5th International Financial Science and Technology Forum opened in Chengdu

At present, financial technology has become a new kinetic energy of the economy, and it is one of the indicators to measure the economic development level of various countries. How financial technology can empower high-quality economic development has also become a hot topic of global concern.

On November 5th, the 5th International Financial Science and Technology Forum opened in Wenjiang District, Chengdu. More than 150 top guests from the world’s political, industrial, academic and research circles once again gathered in Chengdu to analyze the new direction, new track, new trend and new path of China’s economic, financial and technological development around the theme of "digital economy enabling high-quality development". The forum will inject financial power into promoting high-quality economic and social development through more than 10 activities.

The Red Star reporter learned that this two-day forum was sponsored by Southwestern University of Finance and Economics, Chengdu Local Financial Supervision Administration and Wenjiang District People’s Government of Chengdu, and hosted by the School of Finance of Southwestern University of Finance and Economics and China Institute of Finance, Southwestern University of Finance and Economics International Joint Laboratory of Financial Technology, and Southwestern University of Finance and Economics Sichuan Key Laboratory of Financial Intelligence and Financial Engineering.

Vision: Financial Technology Helps Digital China Construction

Today, China’s economic strength has achieved a historic leap, and its total economic output ranks second in the world.

High-quality development has become the primary task for China to build a socialist modernized country in an all-round way, and we must persist in putting the focus of economic development on the real economy.

After several rounds of discussions, the participating experts agreed that financial technology, with its characteristics of integration, accuracy, intersection and openness, has become the key to providing financial support, inciting the capital market and technological innovation, effectively serving the development of real economy and digital economy, helping to strengthen advanced manufacturing industry, realizing high-quality economic development and speeding up the construction of a "manufacturing power" and "digital China".

2022 is a year in which China’s digital economy is fully developed. During the "14th Five-Year Plan" period, China’s digital economy turned to a new stage of deepening application, standardizing development, and universal sharing.

Experts attending the meeting said that, based on this background, this forum is held under the new development pattern of digital economy empowerment. Global financial experts jointly review the process of financial technology innovation, discuss the present situation of financial technology development, and look forward to the wonderful prospect of technology in helping financial service entities, preventing financial risks, and building a digital China and a green China, which is of great significance for forming a wider, wider and deeper opening-up pattern.

Four highlights: groundbreaking technology gives birth to new formats

This forum is carefully prepared and boldly innovated on the basis of previous sessions, and this year presents four new points of view.

The first highlight is that a series of pioneering financial technology systems and platforms were released for the first time at the opening ceremony on November 5th, including AI engineering KubeAI platform, Quant Plus quantitative analysis platform, enterprise risk intelligent identification and early warning system, etc. This is the first time that Southwestern University of Finance and Economics has shown the technical "hard power" of financial universities to the industry, which will bring new products, new models and new formats to the financial technology industry and help enterprises to transform digitally.

The second highlight is that the 5th Chengdu August 80 Global Financial Technology Product Design and R&D Competition officially started, and the competition teams of eight top universities in the world gathered in Chengdu again. The competition will further deepen Industry-University-Research’s cooperation, focus on "new finance and economics" talent training, innovate and standardize the contents of the competition, and innovate the talent training methods.

At the same time, at the Digital Economy Empowerment Financial Technology Innovation Forum held on the same day, the founders of financial technology companies such as Bingjian Technology, Daoke DaoCloud and Kuanbang Technology started a dialogue, focusing on the promotion of enterprise credit evaluation by artificial intelligence technology, AI empowerment investment and other topics to explore the new direction of digital economy development.

In addition, on November 6th, a headmaster’s forum will be held, which will be changed from a closed meeting to an open meeting for the first time. Southwestern University of Finance and Economics will set up a platform to invite the principals and deans of 16 mainstream universities in China to discuss and share new modes, new experiences and new methods of talent cultivation in universities.

Red Star Journalist Wu Huayu According to Wenjiang District

Editor Chai Chang

(Download Red Star News, and report the prize! )

How much did Zhu Ting actually get when he started his Italian league career with an annual salary of 1.2 million? Numbers are touching.

Of course, this is not all the expenses that Zhu Ting needs to deduct. Zhu Ting also needs to pay 1.5%-3% of the agent fees and some miscellaneous expenses of the players’ union. Moreover, because of the talent cultivation, Zhu Ting also needs to pay part of the salary to the Henan mother team. After a full calculation, Zhu Ting’s 1.2 million euros will actually be deducted by nearly 50%, which means that Zhu Ting actually gets 600,000 euros (equivalent to about RMB 4.2 million). But now Zhu Ting obviously doesn’t care about this. To tell the truth, if she wants to make money, Zhu Ting will stay in China. Her annual salary is at least over $1 million, and her income is more than that of studying abroad. Moreover, at home, Zhu Ting has more time to attend business activities, which is also a large amount of income. But for 28-year-old Zhu Ting, she deserves her last chance to fight for her dream. Zhu Ting also knows that if she wants to lead the China women’s volleyball team out of the trough, she must become.

I put the essence of Python coroutine Pa was clean!

This article is a large amount of information, from IO multiplexing, to use the generator, then async, await realization of the principle behind it, in simple terms, the analysis was very thorough, very hardcore!

Two days for personal reasons because it did not touch a long time to write a point of Python, which involves "coroutine" program, the last time out, it is Web framework tornado unique feature, now we have async, await keyword support . Thought about its implementation, reviews the evolution of these years, feel a little bit mean.

They are single-threaded, why the original code with the low efficiency of the async, await add some asynchronous library becomes higher efficiency?

They are single-threaded, why the original code with the low efficiency of the async, await add some asynchronous library becomes higher efficiency?

If you do Python-based network or Web development, this question has puzzled, this article attempts to give an answer.

Before beginning 0x00

Firstly, Not take you browse the source codeAnd then tell you the control to achieve the original code Python standard. Instead, we will set out from the real problems, think of solutions to the problem, step by step evolution path experience solutions, and most importantly, hoping to gain knowledge in a systematic upgrade process.

This article only provides an independent direction of thinking, does not follow the historical and current actual implementation details.

Secondly, you need to read this article familiar with Python, at least understand the concept generator generator of Python.

0x01 IO multiplexing

This is the key to performance. But we are here only to explain the concept, its implementation details is not the point, which we understand Python coroutine enough, as already know enough about, advances to 0x02.

First, you want to know all the network service program is a huge loop, your business logic can be called at some point in this cycle:

defhandler (request):

WHILETRUE:

# Get a new request

request=accept

# To get users to write business logic function according to the route map

Handler=GET_HANDLER (Request)

Handler (Request)

Imagine your Web service of a handler, after receiving a request requires a response to the results of API calls.

For the most traditional network applications, your API requests issued to wait for a response after this time the program stops running, even new requests have to get in after the end of the response. If you rely on an API request packet loss seriously, especially in response to slow it? That will be very low throughput applications.

Many traditional Web server using multi-threading technology to solve this problem: the run handler is placed on other threads, each dealing with a request, this does not affect the new thread blocks request to enter. This problem can be solved to some extent, but for larger systems concurrent, multithreaded scheduling will bring significant performance overhead.

IO multiplexing can be done to solve the problem without the use of threads, it is provided by the operating system kernel functions, we can say specifically for this type of scenario for us. Simply put, your program encounters network IO, tells the operating system to help you staring at, while the operating system gives you a way to make you can feel free to get what IO operation has been completed. like this:

# # 操作 系统 复 复 示 示 例 代代

# Register the ID and type of IO operations to the operating system IO

IO_REGISTER (IO_ID, IO_TYPE)

# Get completed IO operations

Events=IO_GET_FINISHED

For (IO_ID, IO_TYPE) INEvents:

IFIO_TYPE==Read:

Data=read_data (IO_ID)

Elifio_Type==Write:

Write_data (IO_ID, DATA)

Gring the IO multiplex logic into our server, probably like this:

Call_backs={}

Defhandler (REQ):

# do jobs here

DefCall_back (Result):

# Use the returned Result to complete the remaining work …

Call_backs [IO_ID]=CALL_BACK

# New cycle

WHILETRUE:

# Get the completed IO event

IFIO_TYPE==Read: # read

Data=read (IO_ID)

Call_back=call_backs [io_id]

Call_back (data)

Else:

# Other types of IO event processing

PASS

# Get a new request

Handler (Request)

Our Handler has returned immediately for the IO operation. At the same time, each iteration will perform a callback over the completed IO, the network request no longer blocks the entire server.

The pseudo code above is only for understanding, and the details are more complicated. Moreover, it is also possible to connect the new request to the IO event from the operating system to the monitor port.

If we split the cycle part with a call_backs dictionary to a separate module, we can get an EventLoop, which is the iOLOOP provided in the Python Standard Library Asynci.

0x02 with generator to eliminate Callback

He focuses on the Handler function written in our business, after having independent iOLOOP, it now becomes like this:

# 业 业 代 代 … …

# Need an API request

Print (Result)

ask_LOOP.GET_EVENT_LOOP.IO_CALL (API, CALL_BACK)

Here, performance problems have been resolved: We no longer need multi-threads to constantly accept new requests in the source, and don’t have to rely on the API response.

But we have also introduced a new problem. The original business logic code is now demolished. The code before requesting the API is still normal. The code after the request API can only be written in the callback function.

Here our business logic has only one API call. If there are multiple APIs, plus the call to Redis or MySQL (their essential is also a network request), the entire logic will be split, this is a burden on business development .

For some languages ??with anonymous functions (right is Java), it may also trigger a so-called "turning hell".

Next, we find way to solve this problem.

We can easily think that if the function can be suspended after running to the network IO operation, it will wake up at the breakpoint after completion.

If you are familiar with Python’s "Builder", you should find that it happens to have this feature:

Defexample:

Value=yield2

Print ("Get", Value)

ReturnValue

g=esample

# 启 启 生器, we will get 2

Got=G.send (NONE)

Print (got) # 2

TRY:

# Anti-start will display "get 4", which is our incoming value

Got=g.send (got * 2)

ExceptStopItemization ASE:

# Builder runs, will print (4), E.Value is the value of generator return

Print (E.Value)

There is Yield keyword in the function, and the call function will get a generator, and a key method for generator can interact with the generator.

G.send (none) runs the generator code until you encounter Yield, and return to the object, that is, 2, the generator code is stopped here until we perform G.send (got * 2) again, The 2 * 2 is also 4 to assign the value Value in front of Yield, and then continue to run the generator code.

Yield is like a door, you can send a thing from here, you can also take another thing.

If Send makes the generator to run until the next yield is over, the Send call will trigger a special exception STOPITERATION, which comes with a property Value, which is the value of the generator Return.

If we convert our Handler to a generator with Yield keyword, run it to The specific content of IO operationReturns, put the IO result back and restore the generator to run, then solve the problem of uncomfortable business code:

# 业 业 代 代 … …

# Need to execute an API request, directly put the IO request information yield

Result=yieldio_info

# Use the result returned by the API to complete the remaining work

Print (Result)

# This function is registered in iOLOOP, used to call back when there is a new request

Defon_Request (request):

Handler=GET_HANDLER (Request)

g=Handler (Request)

# 首 首 启 获得 获得 i 获得

IO_INFO=G.send (none)

g.send (Result)

ask_LOOP.GET_EVENT_LOOP.IO_CALL (IO_INFO, CALL_BACK)

The above example, the Handler code written by the user will not be dispersed into the callback, and the ON_Request function interacts with Callback and IOLOOP, but it will be implemented in the web framework, which is not visible to the user.

The above code is enough to give us inspiration of Callback destroyed with the builder, but there are two points:

  1. Only a network IO is initiated in business logic, but it is often more

  2. Business logic does not call other asynchronous functions (helping), but in practice, we tend to call other levels.

Let’s take a more complex example:

Among them, Request executes real IO, FUNC1, FUNC2 is only called. Obviously our code can only be written:

Deffunc1:

Ret=yieldfunc2 (re)

returnret

Deffunc2 (DATA):

ReturnResult

DEFREQUEST (URL):

# This simulation returns an IO operation, contains all information about the IO operation, where the string is simplified

Result=yield "IOJOB OF% S"% URL

ReturnResult

For Request, we expose the IO operation to the framework through Yield.

for Func1 and func2, calling request, clearly add Yield keywords Otherwise, the request call returns a generator and will not be paused and continue to perform subsequent logic obviously errors.

This is basically that we don’t write asynchronous code in the Tornado framework without Yield from, Aysnc, AWAIT.

To run the entire calling stack, the approximate process is as follows:

  1. Call FUNC1 to get the generator

  2. Call Send (None) Start it gets the result of request ("http://test.com/foo"), or generator object

  3. Send (none) Starts the generator generated by the request, gets the IO operation, registered by the frame to IOLOOP and specify a callback

  4. The Request Builder wakes up in the callback function after IO, and the generator will go to the return statement end

  5. Capture an exception to get the return value of the Request Builder, wake up the last layer of FUNC1, and get a FUNC2 generator

  6. Continue to execute …

Call FUNC1 to get the generator

Call Send (None) Start it gets the result of request ("http://test.com/foo"), or generator object

Send (none) Starts the generator generated by the request, gets the IO operation, registered by the frame to IOLOOP and specify a callback

The Request Builder wakes up in the callback function after IO, and the generator will go to the return statement end

Capture an exception to get the return value of the Request Builder, wake up the last layer of FUNC1, and get a FUNC2 generator

Continue to execute …

Friends who are familiar with the algorithm and data structure encounter such a traversal logic that will be returned, can be recursively used, because the recursive use generator can not do it, we can use the stack, in fact, this is the word "call stack" origin.

With the stack, we can Connect all generators connected in series in the entire call chain to a generatorFor its constant Send, you can continue to get all IO operation information and drive the call chain advancement, and the implementation method is as follows:

  1. The first generator is in the stack

  2. Call the Send, if you get the generator, you will enter the next round iteration

  3. I encountered IO to ask Yield, let the frame sign up to iOLOOP

  4. After the IO operation is completed, the cache result is forth, enter the next round iteration, the purpose is to restore the upper function using IO results.

  5. If a generator is running, you also need to restore the upper function to the upper function.

The first generator is in the stack

Call the Send, if you get the generator, you will enter the next round iteration

I encountered IO to ask Yield, let the frame sign up to iOLOOP

After the IO operation is completed, the cache result is forth, enter the next round iteration, the purpose is to restore the upper function using IO results.

If a generator is running, you also need to restore the upper function to the upper function.

If implemented, the code is not long but the amount of information is relatively large.

It turns the entire call chain to a generator, calling the send, to complete the IO in the chain, complete these IO, continue to push the logic execution in the calling chain until the overall logic ends:

DEFWrapper (GEN):

# The first layer calls the stack

Stack=stack

Stack.push (gen)

# Start a layer-by-layer call

WHILETRUE:

# Get the top elements of the stack

item=stack.peak

Result=none

IFisgenerator (item):

TRY:

# Try to get the next layer call and get it in the stack

Child=item.send (Result)

Stack.push (child)

# Result Restore to NONE

Result=none

# After entering the stack, enter the next loop directly, continue to explore down

Continue

# If you have an end, you will temporarily save the Result, the next step to make yourself out.

Result=E.Value

Else: # o o operation

# # I 操作 操作, Yield, Io will be woken up and temporarily saved after IO

Result=yieldItem

# 走 到 here, this layer has been completed, out of the stack, the next iteration will be a layer of calling chain

Stack.pop

# 没有有 上, the entire call chain is completed, return

Ifstack.empty:

Print ("finished")

ReturnResult

This may be the most complicated part. If you look hard, it is actually as long as you understand that for the call chain in the example above, it can achieve the effect as follows:

W=Wrapper (Func1)

# Will get "IOJOB of http://test.com/foo"

W.send (none)

# 上 上 ojob foo completed the result "bar" incompart, continue to run, get "IOJOB OF http://test.com/bar"

W.send ("bar")

# 上 上 i i b 完成 完成 传 传 传 传 入 入 入 入 入 入 入 入 入 入 入 入 入

W.send ("BARZ")

With this part, the frame will be added to the matching code:

# Maintain a list of ready lists, store all completed IO events, format is (Wrapper, Result)

Ready=

# After using the wrapper package, you can process IO by Send.

g=wrapper (func1)

# Take the start state directly as the result of NONE

Ready.Append ((g, none))

# Let the iOLOOP perform this function each cycle to handle the ready for IO

Ready.Append ((g, result))

# Traversing all already generators, advance it down

Forg, Result InselF.Ready:

# Use the Result to wake the builder and get the next IO operation

IO_JOB=G.send (Result)

# After the IO operation is complete, add the generator to the ready list, wait for the next round of processing.

ask_LOOP.GET_EVENT_LOOP.IO_CALL (

IO_JOB, LambdareSult: Ready.Append ((g, result)

Here, the core idea is to maintain a list of ready-to-read, and IOLOOP is overwhelmed, and the generator that promotes the ready state is run down, and the new IO operation is registered. After the IO is completed, the ready, after several rounds of Ioloop iteration A Handler will eventually be executed.

At this point, we use the generator to write to write business logic to run normally.

0x04 Improved Scalability

If you can read it here, Python’s scope is basically clear.

We have already achieved one Miniature sweeping frameworkThe realization details of the standard library look great here, but the specific ideas are consistent.

Our equilation framework has a restriction, we can only use IO to operate asynchronously, although in the world of network programming and web programming, the block is basically only IO operation, but there are some exceptions, such as I want the current operation Sleep for a few seconds. The use of time.sleep will make the entire thread to block, requiring special implementation. For example, some CPU-intensive operations can be asynchronously through multi-threaded asynchronous, so that another thread notification event has been completed and followed.

Therefore, it is best to decouple an open space with the network, so that the network IO is only one of the scenes, improves the scalability.

The Python official solution is to let the user hand to block the block code. As for the IOLOOP to register IO event or open a thread completely by yourself, and provide a standard "placeholder" FUTURE, indicating that his results wait for the future Yes, some prototypes are as follows:

ClassFuture:

# Set the result

Defset_Result (Result): Pass

# 获取 结果 结果

Defresult: Pass

# 表示 表示 This Future object is not already set up.

Defdone: Pass

# Set the callback function that should be executed when he is set, you can set multiple

Defadd_done_callback (Callback): Pass

Our slight change can support Future, making the scalability stronger. Network request functions for user code:

# 现在 r es es,, 生 生 器 器 器 器 器 器 器 器

#future is understood as a placeholder

Fut=future

Defcallback (Result):

# Assign the placeholder when the network IO completed the callback

Fut.set_Result (Result)

ask_LOOP.GET_EVENT_LOOP.IO_CALL (URL, CALLBACK)

Now, Request is no longer a generator, but directly returns Future.

And for the function of processing the ready list in the frame:

DEFCALLBACK (FUT):

#future is set to be placed in the ready list

Ready.Append ((g, fut.result))

Fut=g.send (Result)

Fut.add_done_callback (callback)

0x05 development and change

Many years ago, when using Tornado, probably only one Yield keyword is available, the sweeper wants to achieve, that is, this idea, even Yield keywords and return keywords can not appear in a function, you want to run after the generator Returns a value, you need to manually Raise an exception, although the effect is the same as Return now, but it is still very awkward, not elegant.

Later, there was Yield from expression. What can it do?

It is popular, it is done what the generator Wrapper is doing the above: Calling link through the stack, it is the syntax of the Wrapper logic.

With it, the same example you can write:

Deffunc1:

# Note Yield from

Ret=yieldFromRequest ("http://test.com/foo")

# Note Yield from

Ret=yieldfromfunc2 (re)

returnret

Deffunc2 (DATA):

# Note Yield from

Result=yieldfromRequest ("http://test.com/"+data)

ReturnResult

# 同 上 上 实 实 实 实 实 r

Then you no longer need the brainless Wrapper function:

g=func1

# Return the first request for Future

g.send (none)

# Continue to run, automatically enter FUNC2 and get the FUTURE inside it

G.send ("bar")

# Continue to run, complete the residual logic of the call chain, throw the stopiteration exception

G.send ("BARZ")

Yield from the entire call chain directly, it is already great, but it is used asynchronous programming or otherwise, and other languages ??have special-top Async, the AWAIT keyword, until the later version puts these content With dedicated Async, AWAIT keyword packaging, it is a more elegant look today.

0x06 summary and comparison

Overall, Python’s native and trip is achieved from two aspects:

  1. Based on IO multiplexing technology, the entire application is non-blocking on IO, achieving high efficiency

  2. Change the dispersed Callback code through the generator into synchronous code, reducing business writing difficulties

Based on IO multiplexing technology, the entire application is non-blocking on IO, achieving high efficiency

Change the dispersed Callback code through the generator into synchronous code, reducing business writing difficulties

There is a language of the object of the generator. Its IO fight is achieved, the evolution of the Java fight is basically exactly, the keyword is the same, and the Future class is the same than the promise.

However, it is different for this, which is different from this sweeping with the degree of GO-named GO, and does not explicitly based on the generator.

If the class ratio, you can implement the geventime of Python, which is the runtime, and Patch off the system calls to access your own Runtime, you come to the scheduling sweeper, gevent is focused on the network, based on network IO scheduling, relatively simple, The GO achieves perfect multi-core support, more complex and perfect, and creates a new CHANNEL new programming paradigm.

Author: Mao bean peanut

Getting Started: The Most Complete Zero-Basic Python Problem | Zero-Based 8 Months Python | Battle Project | Learning Python is this shortcut

Dry goods: crawling Douban short comment, movie "later we" | 38 years old NBA best player analysis | From Wanzhong to Word! Tang Dynasty 3 disappointment | Laughing to see the new Eti Dragon Slay Dollar | Running Question King | Make a massive Miss in Python Sketch | Disc, I am so fire, I use machine to learn to be a mini recommended system movie

Fun: Poultry Game | Nine Mao Hai | Beautiful Flower | Two-Article Python "Everyday Cool" game!

AI: Robot that will be poetry | Give the picture color | predictive income | Solver, I use the machine to learn to be a mini recommended system movie

Gadget: PDF to Word, easy to get forms and watermarks! | One button saves the HTML page as PDF! Goodbye PDF to extract charges! Use 90 lines of code to create the strongest PDF converter, Word, PPT, Excel, Markdown, HTML one-to-date conversion | Make a staple low-cost ticket prompt! | 60 lines of code made a voice wallpaper switch every day to see a little sister! |

Annual explosion case

  • 1). Lying! PDF to Word Use Python to easily get it!
  • 2) Learn Python is really fragrant! I made a website with 100 lines of code, helping people PS travel pictures, earn a chicken leg to eat
  • 3). The first broadcast over 100 million, hot all net, I analyzed the "Sister Taking Wind and Waves" and found these secrets
  • 4) 80 lines of code! Do a Dream in Python with Python
  • 5). You must master the 20 Python code, short and delicate, useless
  • 6). 30 python hambo skills
  • 7). I summarized 80 "rookie Python selection dry goods.pdf", all dry goods
  • 8). Goodbye Python! I want to learn Go! 2500 word depth analysis!
  • 9). Find a dog welfare! This Python reptile artifact is too cool, automatically download the girl picture