Skip to content

Commit d74e3bc

Browse files
committed
Changes to iotest4.py
1 parent 093f07b commit d74e3bc

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

iotest4.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
# iotest4.py Test PR #3836. Demonstrate the anomaly with a read/write device.
1+
# iotest4.py Test PR #3836.
22
# User class write() performs unbuffered writing.
33
# For simplicity this uses buffered read: unbuffered is tested by iotest2.py.
44

5-
# Run iotest4.test() to see expected output
6-
# iotest4.test(False) to demonstrate the issue.
5+
# This test was to demonstrate the original issue.
6+
# With modified moduselect.c and uasyncio.__init__.py the test now passes.
7+
8+
# iotest4.test() uses separate read and write objects.
9+
# iotest4.test(False) uses a common object (failed without the mod).
710

8-
# Pass/Fail is determined by whether the StreamReader and StreamWriter operate
9-
# on the same (fail) or different (pass) objects.
10-
# I suspect that the issue is with select/ipoll (uasyncio __init__.py)
11-
# The fault is either in select/poll or uasyncio __init__.py.
12-
# As soon as PollEventLoop.add_writer() is called, reading stops.
13-
# PollEventLoop.add_writer() is called when StreamWriter.awrite() issues
14-
# yield IOWrite(self.s), which for unbuffered devices is after the 1st char
15-
# of a multi-char buf is written.
1611

1712
import io, pyb
1813
import uasyncio as asyncio
@@ -25,19 +20,20 @@
2520
MP_STREAM_ERROR = const(-1)
2621

2722
def printbuf(this_io):
28-
print(this_io.wbuf[:this_io.wprint_len])
23+
for ch in this_io.wbuf[:this_io.wprint_len]:
24+
print(chr(ch), end='')
2925

3026
class MyIO(io.IOBase):
3127
def __init__(self, read=False, write=False):
28+
self.ready_rd = False # Read and write not ready
29+
self.wch = b''
3230
if read:
33-
self.ready_rd = False
3431
self.rbuf = b'ready\n' # Read buffer
3532
pyb.Timer(4, freq = 1, callback = self.do_input)
3633
if write:
3734
self.wbuf = bytearray(100) # Write buffer
3835
self.wprint_len = 0
3936
self.widx = 0
40-
self.wch = b''
4137
pyb.Timer(5, freq = 10, callback = self.do_output)
4238

4339
# Read callback: emulate asynchronous input from hardware.

0 commit comments

Comments
 (0)