# Buggy code
def process(args):
    """Run the function in args.name given arguments in args.argfile."""
    # Set environment to standard to use periods for decimals and avoid localization
    os.environ["LC_ALL"] = "C"
    os.environ["LC"] = "C"
    os.environ["LANG"] = "C"
    setpath.prepend_bcbiopath()
    try:
        fn = getattr(multitasks, args.name)
    except AttributeError:
        raise AttributeError(
            "Did not find exposed function in bcbio.distributed.multitasks named '%s'"
            % args.name
        )
    if args.moreargs or args.raw:
        fnargs = [args.argfile] + args.moreargs
        work_dir = None
        argfile = None
    else:
        with open(args.argfile) as in_handle:
            fnargs = yaml.safe_load(in_handle)
        work_dir = os.path.dirname(args.argfile)
        fnargs = config_utils.merge_resources(fnargs)
        argfile = (
            args.outfile
            if args.outfile
            else "%s-out%s" % os.path.splitext(args.argfile)
        )
    if not work_dir:
        work_dir = os.getcwd()
    if len(fnargs) > 0 and fnargs[0] == "cwl":
        fnargs, parallel, out_keys, input_files = _world_from_cwl(
            args.name, fnargs[1:], work_dir
        )
        # Can remove this awkward Docker merge when we do not need custom GATK3 installs
        fnargs = config_utils.merge_resources(fnargs)
        argfile = os.path.join(work_dir, "cwl.output.json")
    else:
        parallel, out_keys, input_files = None, {}, []
    with utils.chdir(work_dir):
        with contextlib.closing(log.setup_local_logging(parallel={"wrapper": "runfn"})):
            try:
                out = fn(*fnargs)
            except:
                logger.exception()
                raise
            finally:
                # Clean up any copied and unpacked workflow inputs, avoiding extra disk usage
                wf_input_dir = os.path.join(work_dir, "wf-inputs")
                if os.path.exists(wf_input_dir) and os.path.isdir(wf_input_dir):
                    shutil.rmtree(wf_input_dir)
    if argfile:
        try:
            _write_out_argfile(
                argfile, out, fnargs, parallel, out_keys, input_files, work_dir
            )
        except:
            logger.exception()
            raise


# Traceback (UnicodeDecodeError)
Traceback (most recent call last):
File "/opt/bcbio/anaconda/lib/python3.6/site-packages/bcbio/distributed/ipythontasks.py", line 52, in _setup_logging
yield config
File "/opt/bcbio/anaconda/lib/python3.6/site-packages/bcbio/distributed/ipythontasks.py", line 447, in detect_sv
return ipython.zip_args(apply(structural.detect_sv, *args))
File "/opt/bcbio/anaconda/lib/python3.6/site-packages/bcbio/distributed/ipythontasks.py", line 80, in apply
return object(*args, **kwargs)
File "/opt/bcbio/anaconda/lib/python3.6/site-packages/bcbio/structural/__init__.py", line 205, in detect_sv
for svdata in caller_fn(items):
File "/opt/bcbio/anaconda/lib/python3.6/site-packages/bcbio/structural/cnvkit.py", line 57, in run
return _cnvkit_by_type(items, background)
File "/opt/bcbio/anaconda/lib/python3.6/site-packages/bcbio/structural/cnvkit.py", line 67, in _cnvkit_by_type
return _run_cnvkit_single(items[0])
File "/opt/bcbio/anaconda/lib/python3.6/site-packages/bcbio/structural/cnvkit.py", line 110, in _run_cnvkit_single
return _associate_cnvkit_out(ckouts, [data])
File "/opt/bcbio/anaconda/lib/python3.6/site-packages/bcbio/structural/cnvkit.py", line 90, in _associate_cnvkit_out
ckout = _add_plots_to_output(ckout, data)
File "/opt/bcbio/anaconda/lib/python3.6/site-packages/bcbio/structural/cnvkit.py", line 640, in _add_plots_to_output
scatter = _add_scatter_plot(out, data)
File "/opt/bcbio/anaconda/lib/python3.6/site-packages/bcbio/structural/cnvkit.py", line 710, in _add_scatter_plot
priority_bed = plot._prioritize_plot_regions(pybedtools.BedTool(priority_bed), data, os.path.dirname(out_file))
File "/opt/bcbio/anaconda/lib/python3.6/site-packages/bcbio/structural/plot.py", line 91, in _prioritize_plot_regions
for r in region_bt:
File "pybedtools/cbedtools.pyx", line 754, in pybedtools.cbedtools.IntervalIterator.__next__
File "/opt/bcbio/anaconda/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 749: ordinal not in range(128)

# Fixed code
def process(args):
    """Run the function in args.name given arguments in args.argfile."""
    # Set environment to standard to use periods for decimals and avoid localization
    locale_to_use = utils.get_locale()
    os.environ["LC_ALL"] = locale_to_use
    os.environ["LC"] = locale_to_use
    os.environ["LANG"] = locale_to_use
    setpath.prepend_bcbiopath()
    try:
        fn = getattr(multitasks, args.name)
    except AttributeError:
        raise AttributeError(
            "Did not find exposed function in bcbio.distributed.multitasks named '%s'"
            % args.name
        )
    if args.moreargs or args.raw:
        fnargs = [args.argfile] + args.moreargs
        work_dir = None
        argfile = None
    else:
        with open(args.argfile) as in_handle:
            fnargs = yaml.safe_load(in_handle)
        work_dir = os.path.dirname(args.argfile)
        fnargs = config_utils.merge_resources(fnargs)
        argfile = (
            args.outfile
            if args.outfile
            else "%s-out%s" % os.path.splitext(args.argfile)
        )
    if not work_dir:
        work_dir = os.getcwd()
    if len(fnargs) > 0 and fnargs[0] == "cwl":
        fnargs, parallel, out_keys, input_files = _world_from_cwl(
            args.name, fnargs[1:], work_dir
        )
        # Can remove this awkward Docker merge when we do not need custom GATK3 installs
        fnargs = config_utils.merge_resources(fnargs)
        argfile = os.path.join(work_dir, "cwl.output.json")
    else:
        parallel, out_keys, input_files = None, {}, []
    with utils.chdir(work_dir):
        with contextlib.closing(log.setup_local_logging(parallel={"wrapper": "runfn"})):
            try:
                out = fn(*fnargs)
            except:
                logger.exception()
                raise
            finally:
                # Clean up any copied and unpacked workflow inputs, avoiding extra disk usage
                wf_input_dir = os.path.join(work_dir, "wf-inputs")
                if os.path.exists(wf_input_dir) and os.path.isdir(wf_input_dir):
                    shutil.rmtree(wf_input_dir)
    if argfile:
        try:
            _write_out_argfile(
                argfile, out, fnargs, parallel, out_keys, input_files, work_dir
            )
        except:
            logger.exception()
            raise