But found that blocking between interface, an interface is accessed, only after the other interface access to come in
So according to the interpretation of online, and joined the
@ tornado. Web. Asynchronous
@ tornado. Gen. Coroutine
Using yield performance of the @ run_on_executor
After each interface to do so, no longer block each other between interface
But the problem is that, even if USES the asynchronous modifier, the same interface, multiple access, or will be executed simultaneously, concurrent,
Such as asynchronous modification of A interface is implemented on A sleep in 10 seconds, two consecutive visit, at the end of the second order only once (10 seconds), will enter,
Search for a long time but could not find the reason, please help solve
Application=tornado, web application ([
(r/test1, test1_handler. Test1),
(r/test2, test2_handler. Test2),
])
If __name__=="__main__" :
Application. Listen (8291)
Tornado. Ioloop. Ioloop. The instance (). The start ()
import logging
The import time
The from concurrent. Futures import ThreadPoolExecutor
The import tornado
The import tornado. Web
The import tornado. Gen
The from tornado. Concurrent import run_on_executor
The from common. Executor_handler import ExecutorInstance
The class test2 (tornado. Web. RequestHandler) :
# executor=ExecutorInstance ()
Executor=ThreadPoolExecutor (4)
@ tornado. Web. Asynchronous
@ tornado. Gen. Engine
Def get (self) :
Yield self. Wait (5)
@ run_on_executor
Def wait (self, s) :
Tag=time. Time ()
Logging. The info (" test2 start % s "% tag)
Time. Sleep (s)
The self. The write (" success ")
Logging. The info (" % s "test2 ended % tag)
The self. The finish ()
As above, two consecutive implement interface the test2, the results are as follows:
The 16:07:15 2019-09-24, 013 - root - INFO - start 1569312435.013742 test2
The 16:07:20 2019-09-24, 019 - root - INFO - end of test2
1569312435.013742The 16:07:20 2019-09-24, 021 - tornado. Access - INFO - 304 GET/test2 (127.0.0.1) 5017.06 ms
The 16:07:20 2019-09-24, 025 - root - INFO - start 1569312440.024935 test2
The 16:07:25 2019-09-24, 027 - root - INFO - end of test2
1569312440.024935The 16:07:25 2019-09-24, 028 - tornado. Access - INFO - 304 GET/test2 (127.0.0.1) 5004.62 ms
You can see the the second execution of waiting for the end of the first to , is this why, how to solve, otherwise no concurrent to speak
CodePudding user response:
Someone you know, give a search direction is also okCodePudding user response:
111111CodePudding user response:
333333CodePudding user response:
Must use two browsers (or two machines) open a request, can see concurrent, opened in a browser, two tabs are notCodePudding user response:
The from tornado. Concurrent import run_on_executorThe from concurrent. Futures import ThreadPoolExecutor
The import tornado
The from tornado import gen
The import tornado. Web
The import time
The class TestHandler (tornado. Web. RequestHandler) :
Executor=ThreadPoolExecutor (2)
@ gen. The coroutine
Def get (self) :
Result=yield self. DoingRunTask ()
The self. The write (result)
@ run_on_executor
Def doingRunTask (self) :
Print (' start ')
Time. Sleep (5)
Print (' end ')
Return 'DDDDDDDDDDD'
Application=tornado, web application ([
(r/test ", "TestHandler),
])
If __name__=="__main__" :
Application. Listen (8000)
Tornado. Ioloop. Ioloop. The instance (). The start ()