File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -1098,7 +1098,9 @@ class which allows multiple tasks to wait on it.
10981098
10991099### 3.6.1 Querying a ThreadSafeFlag
11001100
1101- The state of a ThreadSafeFlag may be tested as follows:
1101+ The ` ThreadSafeFlag ` class has no equivalent to ` Event.is_set ` . A synchronous
1102+ function which returns the state of a ` ThreadSafeFlag ` instance may be created
1103+ as follows:
11021104``` python
11031105import asyncio
11041106from select import poll, POLLIN
@@ -1109,12 +1111,12 @@ async def foo(tsf): # Periodically set the ThreadSafeFlag
11091111 await asyncio.sleep(1 )
11101112 tsf.set()
11111113
1112- def ready (tsf , poller ):
1114+ def ready (tsf , poller ): # Return a function which returns tsf status
11131115 r = (tsf, POLLIN )
11141116 poller.register(* r)
11151117
11161118 def is_rdy ():
1117- return r in poller.ipoll(0 )
1119+ return r in poller.ipoll(0 ) # Immediate return
11181120
11191121 return is_rdy
11201122
@@ -1136,9 +1138,12 @@ async def test():
11361138asyncio.run(test())
11371139```
11381140The ` ready ` closure returns a nonblocking function which tests the status of a
1139- given flag. In the above example ` .wait() ` is not called until the flag has been
1141+ passed flag. In this example ` .wait() ` is not called until the flag has been
11401142set, consequently ` .wait() ` returns rapidly.
11411143
1144+ The ` select.poll ` mechanism works because ` ThreadSafeFlag ` is subclassed from
1145+ ` io.IOBase ` and has an ` ioctl ` method.
1146+
11421147###### [ Contents] ( ./TUTORIAL.md#contents )
11431148
11441149## 3.7 Barrier
You can’t perform that action at this time.
0 commit comments