Skip to content

Commit fbb18cf

Browse files
committed
Change and fix yields to await core.sleep(0)
1 parent e96a12a commit fbb18cf

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

asyncio/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async def wait(self):
5858
self.waiting.push_head(core.cur_task)
5959
# Set calling task's data to the event's queue so it can be removed if needed
6060
core.cur_task.data = self.waiting
61-
core.sleep(0)
61+
await core.sleep(0)
6262
return True
6363

6464

asyncio/lock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async def acquire(self):
6565
# Set calling task's data to the lock's queue so it can be removed if needed
6666
core.cur_task.data = self.waiting
6767
try:
68-
core.sleep(0)
68+
await core.sleep(0)
6969
except core.CancelledError as er:
7070
if self.state == core.cur_task:
7171
# Cancelled while pending on resume, schedule next waiting Task

asyncio/stream.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ async def read(self, n):
5656
This is a coroutine.
5757
"""
5858

59-
yield core._io_queue.queue_read(self.s)
59+
core._io_queue.queue_read(self.s)
60+
await core.sleep(0)
6061
return self.s.read(n)
6162

6263
async def readinto(self, buf):
@@ -67,7 +68,8 @@ async def readinto(self, buf):
6768
This is a coroutine, and a MicroPython extension.
6869
"""
6970

70-
yield core._io_queue.queue_read(self.s)
71+
core._io_queue.queue_read(self.s)
72+
await core.sleep(0)
7173
return self.s.readinto(buf)
7274

7375
async def readexactly(self, n):
@@ -81,7 +83,8 @@ async def readexactly(self, n):
8183

8284
r = b""
8385
while n:
84-
yield core._io_queue.queue_read(self.s)
86+
core._io_queue.queue_read(self.s)
87+
await core.sleep(0)
8588
r2 = self.s.read(n)
8689
if r2 is not None:
8790
if not len(r2):
@@ -98,7 +101,8 @@ async def readline(self):
98101

99102
l = b""
100103
while True:
101-
yield core._io_queue.queue_read(self.s)
104+
core._io_queue.queue_read(self.s)
105+
await core.sleep(0)
102106
l2 = self.s.readline() # may do multiple reads but won't block
103107
l += l2
104108
if not l2 or l[-1] == 10: # \n (check l in case l2 is str)
@@ -158,7 +162,8 @@ async def open_connection(host, port):
158162
except OSError as er:
159163
if er.errno != EINPROGRESS:
160164
raise er
161-
yield core._io_queue.queue_write(s)
165+
core._io_queue.queue_write(s)
166+
await core.sleep(0)
162167
return ss, ss
163168

164169

0 commit comments

Comments
 (0)