code: def write_contigs(asm_uid, contig_uids, batchsize=10000):
      logger.info("Collecting contig data for %s", asm_uid)
      asm_record = Entrez.read(
          entrez_retry(
              Entrez.esummary, db='assembly', id=asm_uid, rettype='text'),
          validate=False)
      asm_organism = asm_record['DocumentSummarySet']['DocumentSummary'][0][
          'SpeciesName']
      try:
          asm_strain = asm_record['DocumentSummarySet']['DocumentSummary'][0][
              'Biosource']['InfraspeciesList'][0]['Sub_value']
      except KeyError:
          asm_strain = ""
      outfilename = "%s.fasta" % os.path.join(args.outdirname, asm_record[
          'DocumentSummarySet']['DocumentSummary'][0]['AssemblyAccession'])
      genus, species = asm_organism.split(' ', 1)
      logger.info("Downloading FASTA records for assembly %s (%s)", asm_uid,
                  ' '.join([genus[0] + '.', species, asm_strain]))
      tries, success = 0, False
      while not success and tries < args.retries:
          records = []
          query_uids = ','.join(contig_uids)
          try:
              for start in range(0, len(contig_uids), batchsize):
                  logger.info("Batch: %d-%d", start, start + batchsize)
                  records.extend(
                      list(
                          SeqIO.parse(
                              entrez_retry(
                                  Entrez.efetch,
                                  db='nucleotide',
                                  id=query_uids,
                                  rettype='fasta',
                                  retmode='text',
                                  retstart=start,
                                  retmax=batchsize), 'fasta')))
              tries += 1
              if len(records) == len(contig_uids):
                  success = True
              else:
                  logger.warning("%d contigs expected, %d contigs returned",
                                 len(contig_uids), len(records))
                  logger.warning("FASTA download for assembly %s failed",
                                 asm_uid)
                  logger.warning("try %d/20", tries)
              logger.info("Downloaded genome size: %d",
                          sum([len(r) for r in records]))
          except:
              logger.warning("FASTA download for assembly %s failed", asm_uid)
              logger.warning(last_exception())
              logger.warning("try %d/20", tries)
      if not success:
          logger.error("Failed to download records for %s (continuing)", asm_uid)
      retval = SeqIO.write(records, outfilename, 'fasta')
      logger.info("Wrote %d contigs to %s", retval, outfilename)