Try changing this:
mc.mcCntlGcodeExecute(inst, g_code)
to 
mc.mcCntlGcodeExecuteWait(inst, g_code)
M30 in MDI is basically a no op if you don't have a pallet changer.  The other thing M30 does is rewind the file, but MDI isn't a file and MDI will not rewind.  So I'm thinking that the MDI is just plain ignoring the M30 and the ends process before the G code gets started.  Hence why I'm thinking the Wait variant of the call should be used.  
Try it and see.
Also, I see you are not checking the return code from the API call.  A lot of mysteries are solved by checking the return codes.  
Steve