Wait for input, but only for a certain amount of time

P

Pif Paf

I have a process, and my process wants to wait for input but only for
a certain amount of time. The input might be coming from a Python file
object (created with popen) or a TCP socket.

What I want is something like:

s = getTimedInput(source, maxDelay)

where:
source = the source of the input
maxDelay = the maximum amount of time we're going to wait for input,
in milliseconds. We wait this amount of time, or a shorter time if we
receive a "\n"(1) in the character stream
s = a string containing the input that was received


(1): or whatever delimiter character we're using.
 
J

Josiah Carlson

Pif said:
I have a process, and my process wants to wait for input but only for
a certain amount of time. The input might be coming from a Python file
object (created with popen) or a TCP socket.

What I want is something like:

s = getTimedInput(source, maxDelay)

where:
source = the source of the input
maxDelay = the maximum amount of time we're going to wait for input,
in milliseconds. We wait this amount of time, or a shorter time if we
receive a "\n"(1) in the character stream
s = a string containing the input that was received


(1): or whatever delimiter character we're using.

If it is a socket on any platform, use select.select().
If it is a file in *nix, use select.select().
If it is a file in windows, check pywin32 (http://sf.net/projects/pywin32)

- Josiah
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top