Without going too far into it; MEL commands perform some checks when certain operations are performed. Things like... updating the available renderer UI or lists, etc. These feedbacks are done after all commands in a script are run and sometimes cause RuntimeErrors if you do not provide the MEL based check in your own script.
This is something I've wrestled with for a little while and found this morning. I'm still not convinced this is the best way to approach the problem, but here it is.
Oh, and this script takes polygon geometry and lights selected and creates/assigns a parti_volume shader, linking lights to the parti-volume to prevent errors, while changing renderer settings to work with a single click.