How to read and print data from a dictionary using a modal operator?
Pass a globals dict to exec

Not sure of the reason why it doesn't work.. only have some inklings.

However can populate a dictionary and pass as globals to the exec function.

        if event.type == 'TIMER':
            mydict = {"a":4}
            myglobals = {"testDict": eval(json.dumps(mydict)),
                       "mylist": ["a","b","c"] }

            msg = 'def printTestFunc(num1,num2):\n'
            msg += '    print(num1)\n'
            msg += '    print(num2)\n'

            msg += 'for i in range(5):\n'
            msg += '    [printTestFunc(0,testDict[key]) for key in mylist if key in testDict]\n'
            exec(msg, myglobals, None)

        return {'PASS_THROUGH'}


Alternatively could define vars in the method and pass locals() which will include self, context and event

Note: Good idea not to use builtins like list and dict for variable names.  EDIT: Oops did just that with globals