Example #1
0
 def save(self):
     """Persist value on disk."""
     f = open(os.path.join(self.path()), 'wb')
     f.write(dumps(self.value))
     f.flush()
     os.fsync(f.fileno())
     f.close()
 def _write(self):
     path = self.path()
     if self.new:
         os.mkdir(path)
     f = open(os.path.join(path, self.version), 'wb')
     f.write(dumps(self.value))
     f.flush()
     os.fsync(f.fileno())
     f.close()
Example #3
0
    def add(self, value):
        self.lock.acquire()

        f = open(self.path(), 'ab')
        f.write('%s\n' % dumps(value))
        f.flush()
        os.fsync(f.fileno())
        f.close()

        self.lock.release()
Example #4
0
 def method(self, *args):
     args = list(args)
     args.insert(0, attribute)
     connection = Client(self.address, authkey=self.authkey)
     connection.send(dumps(args))
     result = loads(connection.recv())
     connection.close()
     if result[0] == 'RESULT':
         return result[1]
     else:
         raise MemoClientException(result[1])
Example #5
0
def main():
    _setproctitle('structurarium.taskqueue')
    parser = argparse.ArgumentParser(
        description='Run Structurarium graph server'
    )
    parser.add_argument(
        '--version',
        '-v',
        action='version',
        version=__version__
    )
    parser.add_argument('host')
    parser.add_argument('port', type=int)
    parser.add_argument('path')
    parser.add_argument('--authkey', '-k')
    parser.add_argument(
        '--worker',
        '-w',
        action='store',
        type=int,
        help='default is set to the number of CPU'
    )
    args = parser.parse_args()
    listener = Listener((args.host, args.port), family='AF_INET')
    database = TaskQueue(args.path, authkey=args.authkey)

    print 'Running on %s:%s' % (args.host, args.port)
    if args.worker > 1:
        pool = Pool(processes=args.worker)
        while True:
            pool = Pool(processes=args.worker)
            connection = listener.accept()
            connection = cPickle.dumps(reduce_connection(connection))
            database.process(connection)
            pool.apply_async(process, [database, connection])
    else:
        print 'monothread'
        database.replay()
        while True:
            connection = listener.accept()
            command = loads(connection.recv())
            output = database.play(command)
            connection.send(dumps(output))
            connection.close()
Example #6
0
 def send_and_recv(self, *args):
     connection = Client(self.address, authkey=self.authkey)
     connection.send(dumps(args))
     result = loads(connection.recv())
     connection.close()
     return result
Example #7
0
 def add(self, identifier, data):
     f = open(os.path.join(self.path(), identifier), 'wb')
     f.write(dumps(data))
     f.flush()
     os.fsync(f.fileno())
     f.close()