A simple wrapper for kqueue VNODE (for now) functionality to be asyncio compatible.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
John-Mark Gurney 18f53e26f9 minor change to the test to make sure that things can cancel properly... há 3 anos
aiokq minor change to the test to make sure that things can cancel properly... há 3 anos
misc add sample program testing if a directory can be watched há 4 anos
.gitignore add a wrapper around kqueue for VNODE that is asyncio friendly. há 4 anos
LICENSE.txt add a wrapper around kqueue for VNODE that is asyncio friendly. há 4 anos
Makefile add a wrapper around kqueue for VNODE that is asyncio friendly. há 4 anos
README.md add function run_on_modify to make usage a bit easier.. há 3 anos
requirements.txt add a wrapper around kqueue for VNODE that is asyncio friendly. há 4 anos
setup.py move to version 1.0.0... Take my own medicine and make it a há 3 anos

README.md

aiokq

This is a module to make select.kqueue module compatible with programs that use asyncio.

The core of kqueue is already implemented via the core asyncio, but other parts of kqueue, like EVFILT_VNODE and EVFILT_PROC are not. This module is currently limited to supporting basic EVFILT_VNODE functionality.

Sample Usage

To watch a file for modification:

import aiokq

fp = open(fname)
async with aiokq.watch_file(fp) as wf:
	while True:
		data = fp.read()
		# do some work on data

		# wait for a modification
		await wf()

The with symantics is required in order to address the race where a write is issued between the registration and the time that you do the read. There is the possibility that a wakeup happens and there are no modifications due to this race.

If you have a function that needed to process a file, you can use the run_on_modify function:

import aiokq
import asyncio

async def processfile(fp, state):
	# process the file in fp
	pass

fp = open(fname)
asyncio.create_task(aiokq.run_on_modify(fp, processfile, []))

The function processfile will be called once initially, to process the file, and then again after each modification. As writes or modifications may happen in blocks, it is entirely possible that processfile will be called in the middle of an update. It is up to the function to use file locking, or another mechanism (append only) to ensure that the file is in a stable state during processing, or simply return waiting for the next modification to complete.