# Buggy code
def _SetTimezone(self, knowledge_base, timezone):
    """Sets the timezone in the knowlege base.

    Args:
      knowledge_base (KnowledgeBase): contains information from the source
          data needed for processing.
      timezone (str): timezone.
    """
    time_zone_str = knowledge_base.GetValue("time_zone_str")
    if time_zone_str:
        default_timezone = time_zone_str
    else:
        default_timezone = timezone

    if not default_timezone:
        default_timezone = "UTC"

    logging.info("Setting timezone to: {0:s}".format(default_timezone))

    try:
        knowledge_base.SetTimezone(default_timezone)
    except ValueError:
        logging.warning(
            "Unsupported time zone: {0:s}, defaulting to {1:s}".format(
                default_timezone, knowledge_base.timezone.zone
            )
        )


# Traceback (WindowsError)
(plaso) C:\dev\plaso>python tools\psort.py -o xlsx G:\test_data\set_1_output.zip -w G:\test_data\set_1_output.xlsx --status_view none -d --analysis browser_search
2016-08-30 12:37:21,882 [INFO] (MainProcess) PID:9376 <psort> Starting analysis plugins.
2016-08-30 12:37:21,888 [DEBUG] (MainProcess) PID:9376 <zeromq_queue> Creating socket for browser_search output event queue
2016-08-30 12:37:21,898 [DEBUG] (MainProcess) PID:9376 <zeromq_queue> browser_search output event queue bound to random port 61649
2016-08-30 12:37:22,417 [INFO] (MainProcess) PID:9376 <psort> Started analysis plugin: browser_search (PID: 14200).
2016-08-30 12:37:24,822 [INFO] (MainProcess) PID:9376 <psort> Analysis plugins running
Traceback (most recent call last):
File "tools\psort.py", line 867, in <module>
if not Main():
File "tools\psort.py", line 853, in Main
tool.ProcessStorage()
File "tools\psort.py", line 787, in ProcessStorage
status_update_callback=status_update_callback)
File "C:\dev\plaso\plaso\frontend\psort.py", line 103, in AnalyzeEvents
status_update_callback=status_update_callback)
File "C:\dev\plaso\plaso\multi_processing\psort.py", line 536, in AnalyzeEvents
storage_writer.Open()
File "C:\dev\plaso\plaso\storage\zip_file.py", line 3217, in Open
self._storage_file.Open(path=self._output_file, read_only=False)
File "C:\dev\plaso\plaso\storage\zip_file.py", line 2754, in Open
self._OpenZIPFile(path, read_only)
File "C:\dev\plaso\plaso\storage\zip_file.py", line 1740, in _OpenZIPFile
os.rename(path, zipfile_path)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process

# Fixed code
def _SetTimezone(self, knowledge_base, timezone):
    """Sets the timezone in the knowledge base.

    Args:
      knowledge_base (KnowledgeBase): contains information from the source
          data needed for processing.
      timezone (str): timezone.
    """
    time_zone_str = knowledge_base.GetValue("time_zone_str")
    if time_zone_str:
        default_timezone = time_zone_str
    else:
        default_timezone = timezone

    if not default_timezone:
        default_timezone = "UTC"

    logging.info("Setting timezone to: {0:s}".format(default_timezone))

    try:
        knowledge_base.SetTimezone(default_timezone)
    except ValueError:
        logging.warning(
            "Unsupported time zone: {0:s}, defaulting to {1:s}".format(
                default_timezone, knowledge_base.timezone.zone
            )
        )