import time

import pyvo

import vohelper


QUERIES = {
  "tgas": ("http://dc.zah.uni-heidelberg.de/tap",
    """SELECT *
        FROM
          tgas.main AS tg
          JOIN TAP_UPLOAD.rave AS mine
          ON (1=CONTAINS(
            POINT('', tg.ra, tg.dec),
            CIRCLE('', mine.raj2000, mine.dej2000, 1/3600.)))"""),
  "rave": ("http://dc.zah.uni-heidelberg.de/tap",
    """SELECT raj2000, dej2000, rv, hmag
        FROM rave.main
        WHERE hmag BETWEEN 8 AND 8.5"""),}


def main():
  with vohelper.SAMP_conn() as conn:
    topcat_id = vohelper.find_client(conn, "topcat")

    svc_url, query = QUERIES["rave"]
    rave_svc = pyvo.dal.TAPService(svc_url)
    job = rave_svc.submit_job(query, maxrec=90000)
    try:
      job.run()
      while job.phase in ('QUEUED', 'EXECUTING'):
        time.sleep(1)
      job.raise_if_error()

      svc_url, query = QUERIES["tgas"]
      tgas_svc = pyvo.dal.TAPService(svc_url)
      result = tgas_svc.run_sync(query,
        uploads={
          "rave":  job.result_uri})

    finally:
      job.delete()

    vohelper.send_table_to(conn, topcat_id, result.table, "rave+tgas")


if __name__=="__main__":
  main()

it is, admittedly, doubtful if having the access url/query pairs in a dictionary like this here. If you inlined them, that’s fair enough.