@@ -1750,7 +1750,16 @@ _Py_read(int fd, void *buf, size_t count)
1750
1750
Py_BEGIN_ALLOW_THREADS
1751
1751
errno = 0 ;
1752
1752
#ifdef MS_WINDOWS
1753
+ _doserrno = 0 ;
1753
1754
n = read (fd , buf , (int )count );
1755
+ int winerr = _doserrno ;
1756
+ if (n < 0 && errno == EINVAL ) {
1757
+ if (winerr == ERROR_NO_DATA ) {
1758
+ /* read() on a non-blocking empty pipe
1759
+ returns EINVAL on Windows */
1760
+ errno = EAGAIN ;
1761
+ }
1762
+ }
1754
1763
#else
1755
1764
n = read (fd , buf , count );
1756
1765
#endif
@@ -1814,7 +1823,14 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held)
1814
1823
Py_BEGIN_ALLOW_THREADS
1815
1824
errno = 0 ;
1816
1825
#ifdef MS_WINDOWS
1826
+ _doserrno = 0 ;
1817
1827
n = write (fd , buf , (int )count );
1828
+ int winerr = _doserrno ;
1829
+ if (n < 0 && errno == ENOSPC ) {
1830
+ /* write() on a non-blocking full pipe
1831
+ returns ENOSPC on Windows */
1832
+ errno = EAGAIN ;
1833
+ }
1818
1834
#else
1819
1835
n = write (fd , buf , count );
1820
1836
#endif
@@ -1829,7 +1845,14 @@ _Py_write_impl(int fd, const void *buf, size_t count, int gil_held)
1829
1845
do {
1830
1846
errno = 0 ;
1831
1847
#ifdef MS_WINDOWS
1848
+ _doserrno = 0 ;
1832
1849
n = write (fd , buf , (int )count );
1850
+ int winerr = _doserrno ;
1851
+ if (n < 0 && errno == ENOSPC ) {
1852
+ /* write() on a non-blocking full pipe
1853
+ returns ENOSPC on Windows */
1854
+ errno = EAGAIN ;
1855
+ }
1833
1856
#else
1834
1857
n = write (fd , buf , count );
1835
1858
#endif
0 commit comments