Tag Archives: python

Multiprocess FOAF fetching with python and rdflib.

Today I’m going to share a little python script, mostly because I’ve been looking for examples on how to do this, and surprise surprise I have found none.

What this script does is to first fetch all foaf:name relations from a list of FOAF cards, and then to display these relations in a friendly manner (e.g. “John Doe knows Jane Doe.”). To do so, the script takes advantage of python’s multiprocessing libraries (Pool, to be more precise), as well as a neat little library called RDFlib. In order to perform SPARQL queries, you need to install the companion rdfextras package which includes a SPARQL plugin implementation:

$ sudo easy_install rdfextras

read more »

Combining inotify and python with pyinotify

While working on a python project recently, I got to the point where I had to monitor a file for modifications. For example, I want to monitor an sqlite database (which is a normal file) to check if I’m the only one modifying it. Fortunately, pyinotify comes to the rescue! Unfortunately, the documentation on their website is a little outdated. Something important to be noted is that pyinotify is based on a Linux Kernel feature called inotify; this means that it’s only available under Linux.

Anyway, after several tries and failures I manage to come up with a decent implementation of a watcher class. The example I’m about to provide uses ThreadedNotifier, since my watcher is supposed to allow my GUI application to run in parallel. Also, please note that you can’t monitor the file itself, but instead you need to monitor the changes to files in a directory! This part was somehow omitted from the documentation; I wonder why.
read more »