<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _parse_metadata(in_handle):
 """Reads metadata from a simple CSV structured input file. samplename,batch,phenotype ERR256785,batch1,normal """

    metadata = {}
    reader = csv.reader(in_handle)
    while 1:
        header = next(reader)
        if not header[0].startswith("#"):
            break
    keys = [x.strip() for x in header[1:]]
    for sinfo in (x for x in reader if x and not x[0].startswith("#")):
        sinfo = [_strip_and_convert_lists(x) for x in sinfo]
        sample = sinfo[0]
        if isinstance(sample, list):
            sample = tuple(sample)
        # sanity check to avoid duplicate rows
        if sample in metadata:
            raise ValueError("Sample %s present multiple times in metadata file.\n"
                             "If you need to specify multiple attributes as a list "
                             "use a semi-colon to separate them on a single line.\n"
                             "https://bcbio-nextgen.readthedocs.org/en/latest/"
                             "contents/configuration.html#automated-sample-configuration\n"
                             "Duplicate line is %s" % (sample, sinfo))
        vals = [_clean_string(v, sinfo) for v in sinfo[1:]]
        metadata[sample] = dict(zip(keys, vals))
    metadata, global_vars = _set_global_vars(metadata)
    return metadata, global_vars