Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 用于触发select()的函数_Python - Fatal编程技术网

Python 用于触发select()的函数

Python 用于触发select()的函数,python,Python,我想用Python编写一个函数,每30秒触发一次select() 到目前为止,我的代码如下所示- 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

我想用Python编写一个函数,每30秒触发一次select()

到目前为止,我的代码如下所示-

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

理想情况下,如果可能的话,我希望在不使用线程的情况下执行此操作。

使用可选的
timeout
参数执行此操作是否有问题

e、 g


使用可选的
timeout
参数进行设置是否有问题

e、 g


@Fletch,如果这有助于您自由接受我的答案(勾选按钮),帮助其他人将来引用此问题。@Fletch,如果这有助于您自由接受我的答案(勾选按钮),帮助其他人将来引用此问题。
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