How can a pilot deal with a magneto failure?
One of the things the checklist will have you do prior to lining up on the runway in a piston engine aircraft is a magneto check. That serves to verify that both magnetos are in good working order and that the grounding of both magnetos is intact.

Typically, that will involve bringing the engine to some given power setting (most likely expressed in terms of RPM, but I suppose it could be measured in some other way for some engines; manifold pressure, maybe?) while holding position, then turn one magneto off, then back on, then turn the other off, then back on. While doing so, you verify that there is a drop in engine power, and that the drop in power is symmetric (about the same for both magnetos), and of course that the engine keeps running on either magneto alone.

This verifies that both ignition systems (magneto, spark plug, etc.) are working, and that the grounding of the magnetos works as expected. Absent the power drop, you could have a hot magneto, which isn't a huge problem in flight but could be a major headache on the ground.

If a magneto fails in flight, especially in a single you might not even notice initially; there will be a slight reduction of engine power, just like during the magneto check, but the engine will keep humming along on the remaining magneto. That's part of the purpose of having two independent ignition systems: redundancy.

If there is an engine failure in flight, the checklist will likely dictate something like "select best magneto" at one point or another during the restart sequence. Basically, you'd be doing a magneto check in the air, and choosing whichever setting gives you more power. If one magneto has failed outright, this will very likely cause the engine to stop when you select only the bad magneto; you'd then have to select the other (or both) and restart the engine again.

The checklist may or may not specify that you should land as soon as possible after a magneto failure, but if it were me, I'd want to land regardless and have the problem checked out properly. That would mean either just landing and taxiing back to the ramp (if, say, you're in the pattern doing circuits), or diverting and landing (if you're on your way to somewhere). There's always the possibility that whatever caused the first magneto to fail might cause the second to fail as well, and I'd rather be on the ground at the wrong airport than in the air with a non-functional engine.