Can I set timeout for the sys.stdin.readline() ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ywzhan

    #1

    Can I set timeout for the sys.stdin.readline() ?

    Hi, I am new here.
    When I use sys.stdin.readl ine() to get input string from user,
    how can I set a timeout value for this operation?
    thank you.

  • Jay Parlar

    #2
    Re: Can I set timeout for the sys.stdin.readl ine() ?


    On Jun 10, 2006, at 5:14 AM, ywzhan wrote:
    [color=blue]
    > Hi, I am new here.
    > When I use sys.stdin.readl ine() to get input string from user,
    > how can I set a timeout value for this operation?
    > thank you.
    >
    >[/color]

    You can do a select() on sys.stdin, and put a timeout on the select, ie:

    rfds, wfds, efds = select.select( [sys.stdin], [], [], 5)

    would give you a five second timeout. If the timeout expired, then rfds
    would be an empty list. If the user entered something within five
    seconds, then rfds will be a list containing sys.stdin.

    Note that by "user entered something", I mean they pressed
    Enter/Return. The select will not exit if they just enter other text.

    Jay P.

    Comment

    Working...