I remember, way back when I lived in Illinois, a police officer in Gary Indiana was eating at a local diner when some thug pulled his pistol from behind and shot him dead. So it has happened, at least once, to a professional police officer.
To answer your question, no, I have not had any particular training for that specific issue. However, I believe most folks would agree that awareness of others in your vicinity, getting close, and especially from behind, should be something to work on. Never let anyone get close from behind. Be aware of someone walking behind you and their position and demeanor. In the few situations where I've had someone walking close behind me, I pretend to be looking around and as I turn my head from side to side, keep an eye on the person following with peripheral vision.
Much of this will do with the holster. Not all holsters are created equal. Some have no retention to speak of, while others are very good. My most recent holster acquisition (for my Ruger P94 .40) has level 2 retention. This would indicate it is more secure than level 1 retention. The holster itself is kydex and fits the pistol snugly. In order to pull my gun, one must have a clean draw. The retention must be released and the weapon pulled in a direction dictated by the cant on this particular holster. Both of those tasks would be awkward and difficult for somebody to do from behind or even from beside me. Meanwhile, for me, it's pretty darn easy to flip the retention with my thumb and pull the pistol.
So a good holster is a real important investment. So is awareness of others around you. If somebody gets too close, I may casually rest my forarm on my pistol. This prevents them from being able to grab the weapon. Considering where the pistol rides on my hip, it is a really natural thing for me to rest my arm across the handle and hammer of my gun. In fact, I do that quite often just because it is comfortable to do so.
Should anyone make a play for my pistol, I'd turn immediately away from the threat. Simply turning my body away from him takes the weapon out of his reach.
Here are a few suggestions:
Unload your gun and holster it. Have a friend try to grab it from your holster from behind. Don't resist but stand in a natural manner. If he can pull your gun easily, you might consider a better holster with more secure retention.
Try having your friend try for your weapon and turn in place and see how easily it moves your pistol out of his reach.
If you can adjust the cant on your holster, tip it forward. This simple tactic makes pulling your weapon by somebody from behind more difficult.
Situations are always going to be different, but if somebody reached for my weapon from behind, I'd spin to the left, moving the gun out of his reach along with my left elbow swinging around to strike the side of his head. There ain't no excuse for somebody to make a play for your gun, so this defensive maneuver is appropriate. As your elbow makes contact with his head, your other hand can be busy taking hold of your weapon.
The reality is this scenario is unlikely to develop. But knowing how you can respond in advance will ensure a favorable outcome for you.
Good luck, and keep thinking when carrying. The two go together just like a gun and ammo.