Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (46 sloc) 1.96 KB
__author__ = 'Cosmo Harrigan'
import socket
import opencog.cogserver
from web.api.apimain import RESTAPI
from threading import Thread
# Endpoint configuration
# To allow public access, set to; for local access, set to
PORT = 5000
class Start(opencog.cogserver.Request):
Implements a CogServer Module to load upon startup that will load the REST
API defined in
See examples @
summary = "Start the OpenCog REST API"
description = "Usage: restapi.Start\n\nStarts the OpenCog REST API. " \
"This will provide a REST interface to the Atomspace,\n" \
"allowing you to create, read, update and delete atoms " \
"across the network using\nHTTP requests/responses with " \
"JSON-formatted data.\n\nDefault endpoint: " \
"\nExample request: " \
def __init__(self):
self.atomspace = None # Will be passed as argument in run method
def run(self, args, atomspace):
self.atomspace = atomspace
make a daemon thread so that it can be interrupted
thread = Thread(target=self.invoke)
print ("REST API is now running in a separate daemon thread.")
def invoke(self):
self.api = RESTAPI(self.atomspace)
# OK, so if the remote end closes the pipe, we get a SIGPIPE
# error, and the server dies. So just restart the server in
# that situation. See bug opencog/ros-behavior-scripting/issues/108
try_again = True
while try_again:
try_again = False
try:, port=PORT)
except socket.error as e:
try_again = True
You can’t perform that action at this time.