Python modules by Rob W.W. Hooft
Although most of the python modules I'm working on are for the data collection
software for the Bruker AXS
Single Crystal Diffraction systems (and can not be redistributed), there are a few nice ones
that I think are more generally applicable.
I'll put them here. Tell me if you use/like/dislike any of this!
- task.py (RCS version 1.28, (2001/02/09))
Manage asynchronous subprocess tasks.
This differs from the 'subproc' package!
After starting the task, we can just:
- 'subproc' connects to the subprocess via pipes
- 'task' lets the subprocess run autonomously.
- ask whether it is finished yet
- wait until it is finished
- perform an 'idle' task (e.g. Tkinter's mainloop) while waiting for
- kill the subprocess with a specific signal
- ask for the exit code.
Another difference of task with 'subproc':
- 'subproc' is a sophisticated os.popen()
- 'task' is a sophisticated os.system()
Differences with the previous version (1.15) which was here:
- If the Task() object is deleted, the child process will stay.
It will never be waited for (i.e., the process will turn into
a zombie. Not a good idea in general).
- AbortableWait will now work also for non-gui applications (just pass
- There is a new class "Attach" that can follow an existing process (very limited).
- Better error handling
- Python 2.0 syntax
Filter stdout and stderr to prevent I/O errors on stdout.
Some people background programs that are producing output on STDOUT
or STDERR. If they close the terminal window after that, the
tty becomes unavailable, and the program might crash when it tries
to write there. Since the stack trace goes to stderr.....
This module replaces stdout and stderr by pseudo-files
that will start writing to a file when IOErrors occur on the tty.
An example program on how to display Numeric arrays using PIL. I have
this problem in my work (See ndisp),
where the data is 16 bit integer, and all 16 bits are
significant. Therefore "dis.py" shows some special features for
scaling any integer or floating point value to an 8-bit displayable
An example of how to do/use enumeration types in python.
An undressed version of the python profiler that prints every call and
return when it is executed. I have used this to trace problems in code
that "crash" the interpreter instead of printing a stack trace (This
can happen for some exceptions in Numeric python, or for gui
code like PyQt).
- comparestrings.py (2005/05/28)
A one-function module to compare short strings and give a similarity score.
The similarity score is based on an algorithm used in Bioinformatics to
compare protein sequences. Letters adjacent to each other on the keyboard
are considered somewhat similar. This can be used to compare commands given
on a keyboard to possible commands of a program. If one possibility stands
out, that is probably what the user meant to type.
This is only suitable for ASCII strings, and probably not much longer than
around 25 characters.
For non-python related issues, see my home page.
Rob Hooft, Last modified May 28, 2005