lokinet/contrib/py/ffi-example/llarp.py
Jeff Becker fbb6913ee9
pep8
2018-05-28 08:23:07 -04:00

43 lines
880 B
Python

#!/usr/bin/env python3
from ctypes import *
import signal
import time
import threading
class LLARP(threading.Thread):
lib = None
ctx = None
def signal(self, sig):
if self.ctx and self.lib:
self.lib.llarp_main_signal(self.ctx, int(sig))
def run(self):
code = self.lib.llarp_main_run(self.ctx)
print("llarp_main_run exited with status {}".format(code))
def main():
llarp = LLARP()
llarp.lib = CDLL("./libllarp.so")
llarp.ctx = llarp.lib.llarp_main_init(b'daemon.ini')
if llarp.ctx:
llarp.start()
try:
while True:
print("busy loop")
time.sleep(1)
except KeyboardInterrupt:
llarp.signal(signal.SIGINT)
finally:
llarp.lib.llarp_main_free(llarp.ctx)
return
if __name__ == '__main__':
main()