i understand the mechanism of corountine in Tornado ,but here is the problem i couldn't figure out,please give me a hand
consider this business routine : here are 5 database operations
#operation 1
#use asynchronous method ,doesn't matter
#switch to other coroutine
#operation 2
#use asynchronous method ,doesn't matter
#switch to other coroutine
#operation 3
#use asynchronous method , but i'll use the result do
#some process then update in operation 4
#switch to other coroutine
#operation 4
#use asynchronous method ,doesn't matter
#switch to other coroutine
#operation 5
#use asynchronous method ,doesn't matter
#switch to other coroutine
as you can see, i don't hope any other related coroutine do update to the same table or same record between each one's operation 3 and operation 4,it'll make dirty read and write.in other words
#coroutine 1 operation 3
#coroutine 2 operation 3
#coroutine 1 operation 4
#coroutine 2 operation 4
would not be accepted, the proper order should be
#coroutine 1 operation 3
#coroutine 1 operation 4
#coroutine 2 operation 3
#coroutine 2 operation 4
i can use block method at operation 3 ,but that'll block the whole server,i hope the main loop would Not execute certain coroutines until i told them to release.
this was silly after i think it over.
this was really really simple and basic in a single thread program practice
global flag
while flag:
do some asynchronous empty callback
flag = True
#operation 3
#use asynchronous method , but i'll use the result do
#some process then update in operation 4
#switch to other coroutine
#operation 4
#use asynchronous method ,doesn't matter
#switch to other coroutine
flag = False
Done.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.