# Buggy code
def _execute(self, jobWrapper, stats, localTempDir, jobStore, fileStore):
    """
    This is the core method for running the job within a worker.
    """
    if stats != None:
        startTime = time.time()
        startClock = getTotalCpuTime()
    baseDir = os.getcwd()
    # Run the job
    returnValues = self.run(fileStore)
    # Serialize the new jobs defined by the run method to the jobStore
    self._serialiseJobGraph(jobWrapper, jobStore, returnValues, False)
    # Add the promise files to delete to the list of jobStoreFileIDs to delete
    for jobStoreFileID in promiseFilesToDelete:
        fileStore.deleteGlobalFile(jobStoreFileID)
    promiseFilesToDelete.clear()
    # Now indicate the asynchronous update of the job can happen

    fileStore._updateJobWhenDone()
    # Change dir back to cwd dir, if changed by job (this is a safety issue)
    if os.getcwd() != baseDir:
        os.chdir(baseDir)
    # Finish up the stats
    if stats != None:
        stats = ET.SubElement(stats, "job")
        stats.attrib["time"] = str(time.time() - startTime)
        totalCpuTime, totalMemoryUsage = getTotalCpuTimeAndMemoryUsage()
        stats.attrib["clock"] = str(totalCpuTime - startClock)
        stats.attrib["class"] = self._jobName()
        stats.attrib["memory"] = str(totalMemoryUsage)


# Traceback (UnicodeDecodeError)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/toil/worker.py", line 408, in <module>
main()
File "/usr/local/lib/python2.7/dist-packages/toil/worker.py", line 392, in main
jobStore.writeStatsAndLogging(ET.tostring(elementNode))
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1126, in tostring
ElementTree(element).write(file, encoding, method=method)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 820, in write
serialize(write, self._root, encoding, qnames, namespaces)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 939, in _serialize_xml
_serialize_xml(write, e, encoding, qnames, None)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 939, in _serialize_xml
_serialize_xml(write, e, encoding, qnames, None)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 937, in _serialize_xml
write(_escape_cdata(text, encoding))
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1073, in _escape_cdata
return text.encode(encoding, "xmlcharrefreplace")
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 48: ordinal not in range(128)

# Fixed code
def _execute(self, jobWrapper, stats, localTempDir, jobStore, fileStore):
    """
    This is the core method for running the job within a worker.
    """
    if stats != None:
        startTime = time.time()
        startClock = getTotalCpuTime()
    baseDir = os.getcwd()
    # Run the job
    returnValues = self.run(fileStore)
    # Serialize the new jobs defined by the run method to the jobStore
    self._serialiseJobGraph(jobWrapper, jobStore, returnValues, False)
    # Add the promise files to delete to the list of jobStoreFileIDs to delete
    for jobStoreFileID in promiseFilesToDelete:
        fileStore.deleteGlobalFile(jobStoreFileID)
    promiseFilesToDelete.clear()
    # Now indicate the asynchronous update of the job can happen

    fileStore._updateJobWhenDone()
    # Change dir back to cwd dir, if changed by job (this is a safety issue)
    if os.getcwd() != baseDir:
        os.chdir(baseDir)
    # Finish up the stats
    if stats != None:
        stats.jobs.time = str(time.time() - startTime)
        totalCpuTime, totalMemoryUsage = getTotalCpuTimeAndMemoryUsage()
        stats.jobs.clock = str(totalCpuTime - startClock)
        stats.jobs.class_name = self._jobName()
        stats.jobs.memory = str(totalMemoryUsage)