Python select.html() Examples
The following are 7
code examples of select.html().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
select
, or try the search function
.
Example #1
Source File: kqreactor.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def __init__(self, _kqueueImpl=select): """ Initialize kqueue object, file descriptor tracking dictionaries, and the base class. See: - http://docs.python.org/library/select.html - www.freebsd.org/cgi/man.cgi?query=kqueue - people.freebsd.org/~jlemon/papers/kqueue.pdf @param _kqueueImpl: The implementation of L{_IKQueue} to use. A hook for testing. """ self._impl = _kqueueImpl self._kq = self._impl.kqueue() self._reads = set() self._writes = set() self._selectables = {} posixbase.PosixReactorBase.__init__(self)
Example #2
Source File: kqreactor.py From learn_python3_spider with MIT License | 6 votes |
def __init__(self, _kqueueImpl=select): """ Initialize kqueue object, file descriptor tracking dictionaries, and the base class. See: - http://docs.python.org/library/select.html - www.freebsd.org/cgi/man.cgi?query=kqueue - people.freebsd.org/~jlemon/papers/kqueue.pdf @param _kqueueImpl: The implementation of L{_IKQueue} to use. A hook for testing. """ self._impl = _kqueueImpl self._kq = self._impl.kqueue() self._reads = set() self._writes = set() self._selectables = {} posixbase.PosixReactorBase.__init__(self)
Example #3
Source File: pyinotify.py From hacker-scripts with MIT License | 5 votes |
def __init__(self, watch_manager, default_proc_fun=None, read_freq=0, threshold=0, timeout=None): """ Initialization, initialize base classes. read_freq, threshold and timeout parameters are used when looping. @param watch_manager: Watch Manager. @type watch_manager: WatchManager instance @param default_proc_fun: Default processing method. See base class. @type default_proc_fun: instance of ProcessEvent @param read_freq: if read_freq == 0, events are read asap, if read_freq is > 0, this thread sleeps max(0, read_freq - (timeout / 1000)) seconds. @type read_freq: int @param threshold: File descriptor will be read only if the accumulated size to read becomes >= threshold. If != 0, you likely want to use it in combination with an appropriate value set for read_freq because without that you would keep looping without really reading anything and that until the amount of events to read is >= threshold. At least with read_freq you might sleep. @type threshold: int @param timeout: see read_freq above. If provided, it must be set in milliseconds. See https://docs.python.org/2/library/select.html#select.poll.poll @type timeout: int """ # Init threading base class threading.Thread.__init__(self) # Stop condition self._stop_event = threading.Event() # Init Notifier base class Notifier.__init__(self, watch_manager, default_proc_fun, read_freq, threshold, timeout) # Create a new pipe used for thread termination self._pipe = os.pipe() self._pollobj.register(self._pipe[0], select.POLLIN)
Example #4
Source File: filebeat.py From filebeat.py with MIT License | 5 votes |
def tail_file(file_path, from_head=False): """ 创建子进程tail file Args: file_path: 文件路径 from_head: 是否重头开始读取文件 Returns: """ # 安全注释, 防止OP不小心kill子进程 safe_comment = "'(Do not kill me, parent PID: %d)'" % os.getpid() if from_head is True: # 先输出现有文件全部内容, 然后tail文件 # -F 当文件变化时能切换到新的文件 cmd = "cat %s && tail -F %s %s" % (file_path, file_path, safe_comment) else: cmd = "tail -F %s %s" % (file_path, safe_comment) try: process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, bufsize=-1) except OSError as e: return False, str(e) else: # https://docs.python.org/2/library/select.html poll = select.epoll() poll.register(process.stdout) return process, poll
Example #5
Source File: pyinotify.py From recursive-gobuster with MIT License | 5 votes |
def __init__(self, watch_manager, default_proc_fun=None, read_freq=0, threshold=0, timeout=None): """ Initialization, initialize base classes. read_freq, threshold and timeout parameters are used when looping. @param watch_manager: Watch Manager. @type watch_manager: WatchManager instance @param default_proc_fun: Default processing method. See base class. @type default_proc_fun: instance of ProcessEvent @param read_freq: if read_freq == 0, events are read asap, if read_freq is > 0, this thread sleeps max(0, read_freq - (timeout / 1000)) seconds. @type read_freq: int @param threshold: File descriptor will be read only if the accumulated size to read becomes >= threshold. If != 0, you likely want to use it in combination with an appropriate value set for read_freq because without that you would keep looping without really reading anything and that until the amount of events to read is >= threshold. At least with read_freq you might sleep. @type threshold: int @param timeout: see read_freq above. If provided, it must be set in milliseconds. See https://docs.python.org/3/library/select.html#select.poll.poll @type timeout: int """ # Init threading base class threading.Thread.__init__(self) # Stop condition self._stop_event = threading.Event() # Init Notifier base class Notifier.__init__(self, watch_manager, default_proc_fun, read_freq, threshold, timeout) # Create a new pipe used for thread termination self._pipe = os.pipe() self._pollobj.register(self._pipe[0], select.POLLIN)
Example #6
Source File: pyinotify.py From hacker-scripts with MIT License | 4 votes |
def __init__(self, watch_manager, default_proc_fun=None, read_freq=0, threshold=0, timeout=None): """ Initialization. read_freq, threshold and timeout parameters are used when looping. @param watch_manager: Watch Manager. @type watch_manager: WatchManager instance @param default_proc_fun: Default processing method. If None, a new instance of PrintAllEvents will be assigned. @type default_proc_fun: instance of ProcessEvent @param read_freq: if read_freq == 0, events are read asap, if read_freq is > 0, this thread sleeps max(0, read_freq - (timeout / 1000)) seconds. But if timeout is None it may be different because poll is blocking waiting for something to read. @type read_freq: int @param threshold: File descriptor will be read only if the accumulated size to read becomes >= threshold. If != 0, you likely want to use it in combination with an appropriate value for read_freq because without that you would keep looping without really reading anything and that until the amount of events to read is >= threshold. At least with read_freq set you might sleep. @type threshold: int @param timeout: see read_freq above. If provided, it must be set in milliseconds. See https://docs.python.org/2/library/select.html#polling-objects @type timeout: int """ # Watch Manager instance self._watch_manager = watch_manager # File descriptor self._fd = self._watch_manager.get_fd() # Poll object and registration self._pollobj = select.poll() self._pollobj.register(self._fd, select.POLLIN) # This pipe is correctely initialized and used by ThreadedNotifier self._pipe = (-1, -1) # Event queue self._eventq = deque() # System processing functor, common to all events self._sys_proc_fun = _SysProcessEvent(self._watch_manager, self) # Default processing method self._default_proc_fun = default_proc_fun if default_proc_fun is None: self._default_proc_fun = PrintAllEvents() # Loop parameters self._read_freq = read_freq self._threshold = threshold self._timeout = timeout # Coalesce events option self._coalesce = False # set of str(raw_event), only used when coalesce option is True self._eventset = set()
Example #7
Source File: pyinotify.py From recursive-gobuster with MIT License | 4 votes |
def __init__(self, watch_manager, default_proc_fun=None, read_freq=0, threshold=0, timeout=None): """ Initialization. read_freq, threshold and timeout parameters are used when looping. @param watch_manager: Watch Manager. @type watch_manager: WatchManager instance @param default_proc_fun: Default processing method. If None, a new instance of PrintAllEvents will be assigned. @type default_proc_fun: instance of ProcessEvent @param read_freq: if read_freq == 0, events are read asap, if read_freq is > 0, this thread sleeps max(0, read_freq - (timeout / 1000)) seconds. But if timeout is None it may be different because poll is blocking waiting for something to read. @type read_freq: int @param threshold: File descriptor will be read only if the accumulated size to read becomes >= threshold. If != 0, you likely want to use it in combination with an appropriate value for read_freq because without that you would keep looping without really reading anything and that until the amount of events to read is >= threshold. At least with read_freq set you might sleep. @type threshold: int @param timeout: see read_freq above. If provided, it must be set in milliseconds. See https://docs.python.org/3/library/select.html#select.poll.poll @type timeout: int """ # Watch Manager instance self._watch_manager = watch_manager # File descriptor self._fd = self._watch_manager.get_fd() # Poll object and registration self._pollobj = select.poll() self._pollobj.register(self._fd, select.POLLIN) # This pipe is correctely initialized and used by ThreadedNotifier self._pipe = (-1, -1) # Event queue self._eventq = deque() # System processing functor, common to all events self._sys_proc_fun = _SysProcessEvent(self._watch_manager, self) # Default processing method self._default_proc_fun = default_proc_fun if default_proc_fun is None: self._default_proc_fun = PrintAllEvents() # Loop parameters self._read_freq = read_freq self._threshold = threshold self._timeout = timeout # Coalesce events option self._coalesce = False # set of str(raw_event), only used when coalesce option is True self._eventset = set()