non-blocking sys.stdin.read() on win32? 
Author Message
 non-blocking sys.stdin.read() on win32?

Hi all.

I'm making a replacement for rsh/ssh to be used by cvs's
-d:ext: option.. CVS opens my program and sends data to it
as if it were rsh. My program sends that data to a socket
and then reads the response, which comes from a cvs server.

Everything seems to work fine, but it's INCREDIBLY slow,
because I only read one line at a time from stdin (the local
cvs parent process):

Quote:
>>> local_msg = sys.stdin.readline()

I want to just be able to call select() on sys.stdin and
then, if appropriate, read more than one line of, but it
doesn't let me, because on win32, python's select() only
works for sockets.

What can I do?

(I'm not above using a C extension if that's what it takes,
but I'm not much of a C programmer)

Cheers,


------------------------------------------------------------
Give your ideas the perfect home: http://www.*-*-*.com/
 cvs - weblogs - php - linux shell - perl/python/cgi - java
------------------------------------------------------------



Fri, 09 Jul 2004 09:01:29 GMT  
 non-blocking sys.stdin.read() on win32?

Quote:

> I want to just be able to call select() on sys.stdin and
> then, if appropriate, read more than one line of, but it
> doesn't let me, because on win32, python's select() only
> works for sockets.

Use two threads: one with a read/send loop and one with
a recv/write loop.

Another possibility is win32event.  But that can get rather
involved.

## Jason Orendorff    http://www.jorendorff.com/



Fri, 09 Jul 2004 09:39:32 GMT  
 non-blocking sys.stdin.read() on win32?
There's no way to do non-blocking I/O on STDIN on a Win32.
I don't know why and even never bothered to test it, but I
suppose we can trust Sam Rushing: he did try.

From Medusa/monitor_client_win32.py:

  # monitor client, win32 version

  # since we can't do select() on stdin/stdout, we simply
  # use threads and blocking sockets.  <sigh>

Sorry to bring bad news,

Laurent

Quote:

> Hi all.

> I'm making a replacement for rsh/ssh to be used by cvs's
> -d:ext: option.. CVS opens my program and sends data to it
> as if it were rsh. My program sends that data to a socket
> and then reads the response, which comes from a cvs server.

> Everything seems to work fine, but it's INCREDIBLY slow,
> because I only read one line at a time from stdin (the local
> cvs parent process):

> >>> local_msg = sys.stdin.readline()

> I want to just be able to call select() on sys.stdin and
> then, if appropriate, read more than one line of, but it
> doesn't let me, because on win32, python's select() only
> works for sockets.

> What can I do?

> (I'm not above using a C extension if that's what it takes,
> but I'm not much of a C programmer)

> Cheers,


> ------------------------------------------------------------
> Give your ideas the perfect home: http://www.cornerhost.com/
>  cvs - weblogs - php - linux shell - perl/python/cgi - java
> ------------------------------------------------------------



Fri, 09 Jul 2004 10:08:52 GMT  
 non-blocking sys.stdin.read() on win32?

Quote:

> > I want to just be able to call select() on sys.stdin and
> > then, if appropriate, read more than one line of, but it
> > doesn't let me, because on win32, python's select() only
> > works for sockets.

> Use two threads: one with a read/send loop and one with
> a recv/write loop.

Thanks Jason (and Laurent)!

I borrowed some of Sam's code from Medusa...

I'll post what this is all about as soon as I figure out one
last piece...

Cheers,


------------------------------------------------------------
Give your ideas the perfect home: http://www.cornerhost.com/
 cvs - weblogs - php - linux shell - perl/python/cgi - java
------------------------------------------------------------



Fri, 09 Jul 2004 12:02:30 GMT  
 non-blocking sys.stdin.read() on win32?

Quote:

> There's no way to do non-blocking I/O on STDIN on a Win32.
> I don't know why and even never bothered to test it, but I
> suppose we can trust Sam Rushing: he did try.

> From Medusa/monitor_client_win32.py:

>   # monitor client, win32 version

>   # since we can't do select() on stdin/stdout, we simply
>   # use threads and blocking sockets.  <sigh>

From what I heard (I don't do Windows myself):

* select() just works with sockets on win32

* there is a family of syscalls having about the same
  functionality as select on Unix. Something like "WaitForEvent()"
  or so.

drt

--
{*filter*}age mutant ninja hero coders from da c0re - http://www.*-*-*.com/
me                                  - http://www.*-*-*.com/ ~drt/



Sun, 11 Jul 2004 09:30:31 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Non-blocking STDIN read?

2. read stdin NON-BLOCKING

3. non-blocking reading from stdin?

4. using sys.stdin.raw_input and sys.stdin.readline together in a platform independent way

5. banging head against sys.stdin and tkinter on win32

6. sys.stdin.read() HELP!

7. Error using sys.stdin.read()

8. can i make sys.stdin.read() not wait?

9. Terminal reads and sys.stdin

10. Problems reading fra sys.stdin and later on duing raw_input

11. stdin non blocking and fileevent

12. How do I get a non-blocking stdin?

 

 
Powered by phpBB® Forum Software