In a large pot, melt the butter over medium heat. Add the onions all at once and a small splash of water. Season the onions with salt and pepper. Bring the onions to a simmer, stirring often. Reduce the heat if the onions begin to cook too fast. Cook until the onions are soft and translucent, about 15 minutes. (If you want a sweeter soup, continue to cook the onions until they caramelize to the richness of your preference.)
Add the flour and cook for 3 minutes. Add the sherry and cook for a few minutes longer. Add the beef stock and bring to a very low simmer; simmer for about 35 minutes.
Preheat the broiler to finish the soup.
Add the thyme to the soup and simmer for 5 more minutes. Season with salt and pepper as needed. Remove the herbs.
Ladle the soup into 4 soup crocks. Cover each crock with 2 slices of cheese and some croutons, then top with the shredded Gruyere. Transfer the crocks to a baking sheet and place under the broiler until the cheese bubbles and browns.