1

30秒ごとにselect()をトリガーする関数をPythonで記述したいと思います。

これまでのところ、私のコードは次のようになっています-

inputs = [ UDPSock , sys.stdin]
outputs = []
while inputs:
  readable, writable, exceptional = select.select(inputs, outputs, inputs)
  for s in readable:
    if s is UDPSock
      # Deal with socket

    elif s is sys.stdin:
      # Deal with input

-の線に沿って何かを達成したい

inputs = [ UDPSock , sys.stdin, timer]
outputs = []
while inputs:
  readable, writable, exceptional = select.select(inputs, outputs, inputs)
  for s in readable:
    if s is UDPSock
      # Deal with socket

    elif s is sys.stdin:
      # Deal with input

    elif s is timer:
      # Deal with  timer

理想的には、可能であればスレッドを使用せずにこれを実行したいと思います。

4

1 に答える 1

4

timeoutオプションのパラメータを使用して選択することに問題がありますか?

例えば

while True:
    ready = readable, writable, exceptional = select.select(inputs, outputs,
                                                            inputs, 30.0)
        if not any(ready):
            #timeout condition
        else:
            #iterate over the ready lists as appropriate
于 2012-12-17T20:27:57.120 に答える