I have this problem and all ways found that when it happens i knock it into 2nd gear rock the bike back and forth and it all ways starts.
might help if your just trying to get it home
If anyone doubts their ability to do this, I have very little technical knowledge (@barbagris will testify to that!) and it took me 30 mins from unbolting the starter to firing her up again, and for £13.50, bargain!
The very first thing to check (after fundamental battery check) is to see if the headlights go out when you hold clutch/press start
Either they do go out (which they should) or don't, either way gives big clue as to where issue might be.
From the seat it looks like it just dims, but if you actually look at the lights they go out, and the little parking lights below the main lights stay on.