def trace(self, frame, event, arg):
        try:
            # It's very important not to write to frame.f_locals directly.
            # Apparently, each time we directly access the f_locals, member
            # of a frame object, it calls some C code and syncs to its current
            # "internal" values. What we do instead is just read it out once,
            # at the beginning of the function, and then the writes will be seen later.
            # (see https://utcc.utoronto.ca/~cks/space/blog/python/FLocalsAndTraceFunctions
            # for a more full discussion, which led us to this approach)

            f_locals = frame.f_locals

            globalsToSet = self.blockOperation(frame)

            policyInstances = {}

            for keyname in list(globalsToSet.keys()):
                policyInstances[keyname] = self.downloadPolicy.initiatePolicyCheck(keyname, globalsToSet[keyname])

            for k, _ in globalsToSet.iteritems():
                f_locals[k] = self.downloadPolicy.resolveToFinalValue(policyInstances[k])
        except (Exceptions.PythonToForaConversionError, Exceptions.ForaToPythonConversionError) as err:
            frame.f_lineno = frame.f_lineno - 1
            # re-raise to hide from users the traceback into the internals of pyfora
            logging.error("Re-raising exception to partially hide traceback.\n%s", traceback.format_exc())
            raise err
        except Exception:
            frame.f_lineno = frame.f_lineno - 1
            logging.error("Re-raising exception after amending lineno.\n%s", traceback.format_exc())
            raise

        if self.traceAndException is not None:
            exceptionValue = self.traceAndException[1]
            tb = syntheticTraceback(self.traceAndException[0])

            #setting the line number causes the trace to not call __exit__ and instead to
            #resume in the parent stackframe at the with block itself with the raised exception.
            #This causes the trace to contain two frames for the calling 'with' block, which is
            #not optimal, but it's better than the alternative which is to have the line-number
            #at the end of the 'with' block, which is just confusing.
            frame.f_lineno = frame.f_lineno-1
            raise exceptionValue, None, tb

        raise WithBlockCompleted()
dataset/ETHPy150Open ufora/ufora/packages/python/pyfora/WithBlockExecutor.py/WithBlockExecutor.trace/original