Skip to content

Instantly share code, notes, and snippets.

@sauercrowd
Created August 29, 2019 18:47
Show Gist options
  • Save sauercrowd/1a1d7ece4b6dc129700d4126b6aa9e2d to your computer and use it in GitHub Desktop.
Save sauercrowd/1a1d7ece4b6dc129700d4126b6aa9e2d to your computer and use it in GitHub Desktop.
PyQuil qvm/quilc check
import socket
from pyquil.api import ForestConnection
x = ForestConnection()
# try to connect to qvm port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(('127.0.0.1', 5000))
# something is listening, check if it's actually a qvm service
x._qvm_get_version_info()
except ConnectionRefusedError:
print("starting a new qvm instance")
# nothing running, now start a new qvm instance
except Exception:
# something completely bad happened, log error and exit
print("something bad happened, exiting...")
print(e)
finally:
s.close()
# same for quilc
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(('127.0.0.1', 5555))
x._quilc_get_version_info()
except ConnectionRefusedError:
print("starting a new quilc instance")
# nothing running, now start a new quilc instance
except Exception as e:
# something completely bad happened, log error and exit
print("something bad happened, exiting...")
print(e)
finally:
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment