Esempio n. 1
0
    def post(self, request):
        requested_interval = request.json.get('interval')
        requested_url = request.json.get('url')

        try:
            if validators.url(requested_url) is not True:
                return response.HTTPResponse(body="Malformatted URL",
                                             status=400)
        except TypeError:
            return response.HTTPResponse(body="URL is not a string",
                                         status=400)

        try:
            if requested_interval < 1:
                return response.HTTPResponse(body="Interval smaller than 1",
                                             status=400)
        except TypeError:
            return response.HTTPResponse(body="Interval cannot be a string",
                                         status=400)

        # remove trailing / from URL
        requested_url = re.sub(r"/+$", "", requested_url)

        # check if we have this url registered in redis
        redis_id = r.get_id_from_url(requested_url)
        if redis_id is None:
            redis_id = r.add_url(requested_url, requested_interval)
            worker_input = {'site': requested_url, 'interval':
                            requested_interval}
            rpt = multitimer.RepeatingTimer(interval=requested_interval,
                                            function=self.worker_func,
                                            kwargs=worker_input,
                                            count=-1, runonstart=False)
            rpt.start()
            timers_table[redis_id] = rpt
        else:
            redis_id = int(redis_id.decode("utf-8"))
            r.update_interval(redis_id, requested_interval)
            timers_table[redis_id].stop()
            worker_input = {'site': requested_url, 'interval':
                            requested_interval}
            rpt = multitimer.RepeatingTimer(interval=requested_interval,
                                            function=self.worker_func,
                                            kwargs=worker_input,
                                            count=-1,
                                            runonstart=False)
            rpt.start()
            timers_table[redis_id] = rpt

        return text("{\"id\": %s}" % redis_id)
 def __init__(self, function, interval: int):
     self.function = function
     self.interval = interval
     self.timer = multitimer.RepeatingTimer(interval=self.interval,
                                            function=self.function,
                                            count=sys.maxsize,
                                            runonstart=False)
Esempio n. 3
0
def main():
    print("\n" + "sub-programs start executing")
    for i in range(0, (len(line) - 1)):
        #print(line[i])
        program_name = (line[i].split(' '))[0]
        if not os.path.isfile(program_name):
            #print(program_name)
            print("FileError:" + program_name, "is missing")
            sys.exit(1)
        os.system("python3 {0} ".format(line[i]))
        pid = os.popen(
            "ps -ef | grep {0} | grep -v grep".format(program_name)).read()
        print(program_name, "is started executing " + "\n" + pid)

    #buffer_request_timer=multitimer.RepeatingTimer(interval=2, function=monitor).start()
    buffer_request_timer = multitimer.RepeatingTimer(
        interval=15, function=monitorr).start()
Esempio n. 4
0
import multitimer
from time import perf_counter, sleep
from pprint import pprint


#%%
def test_func():
    raw_times.append(perf_counter() - rpt.starttime)


raw_times = []
interval = 0.1
rpt = multitimer.RepeatingTimer(interval=interval, ontimeout=test_func, count=10)
rpt.start()

sleep(1.5)

a0 = raw_times[0]
intervals = [t - a0 for t in raw_times]
offsets = [t % interval for t in intervals]

print('Intervals:')
pprint(intervals)

print('\nOffsets from ideal intervals:')
pprint(offsets)


#%%
result = []
def increment_func():
Esempio n. 5
0
            cv.imshow("video", frame)

            if recorder is not None:
                recorder.write_frame(frame)

        if cv.waitKey(1) & 0xFF == ord('q'):
            break
            

    vcap.release()
    timer.stop()
    recorder.close_stream(full_stop=True)
    cv.destroyAllWindows()





vcap = cv.VideoCapture("udp://192.168.0.32:5000/")
recorder = None
# How often the stream should be saved to harddrive (mins)
time_interval = 20
timer = multitimer.RepeatingTimer(time_interval, recorder.close_stream, count=-1, runonstart=False) # timer that repeats every interval
timer_rec = multitimer.MultiTimer(8, start_recorder, kwargs=dict(recorder), runonstart=False)

if vcap.isOpened():
    timer.start()
    timer_rec.start()
    main_loop()

Esempio n. 6
0
                                  "%Y-%m-%dT%H-%M-%S")
    handler.setFormatter(formatter)

    console_handler = logging.StreamHandler()
    console_handler.setFormatter(formatter)

    logger.addHandler(console_handler)
    logger.addHandler(handler)


if __name__ == '__main__':
    setup_logging()

    token = os.getenv('DISCORD_TOKEN')
    guild_id = int(os.getenv('UNIT_GUILD_ID'))

    loop = asyncio.get_event_loop()
    try:
        timer = multitimer.RepeatingTimer(interval=30,
                                          function=check_tig_expired)
        timer.start()
        bot.add_listener(on_message, 'on_message')
        loop.run_until_complete(bot.start(token))
    except KeyboardInterrupt:
        loop.run_until_complete(bot.logout())
    except LoginFailure as ex:
        logger.info(f"Login failure, maybe invalid token passed? '{token}'")
    finally:
        loop.stop()
        loop.close()