Heat the oil in a large heavy based pan. Cook the onions really slowly over a low heat for 30 minutes or until they have softened so much that they have become caramelized. Add the sugar, chilli and thyme and cook for a further 10 minutes.
Pour over the wine vinegar, red wine and port and simmer, uncovered for 20 minutes, stirring every so often. You want the onions to become a deep red colour and there to only be a small pool of liquid floating around the bottom of the pan and when you draw a wooden spoon through the jam a path clears before filling again with syrupy juices.
Cool the onions in the pan then fill sterilized jam jars with the mixture. It can be eaten straight away but tastes really great when it has had a couple of weeks to mature.