def refresh_collector(collector: Collector): local_db = SQLClient(config, model_class=Model) while True: if not local_db.query(Collector).get(collector.id): print(f'Collector {collector.id} exited') exit(0) if collector.type == 'slido': refresh_slido_with_retry(collector.hash) elif collector.type == 'youtube': print('TODO') time.sleep(5)
db.session.add(user) db.session.commit() print('Added') def del_user(username): db.query(User).filter(User.username==username).delete() db.session.commit() print("Deleted") parser = argparse.ArgumentParser(description="Add user") subparser = parser.add_subparsers(title='subcommands', description='valid subcommands', help='sub-command help') add_parser = subparser.add_parser('add') add_parser.set_defaults(command='add') # https://coderedirect.com/questions/205072/argparse-identify-which-subparser-was-used add_parser.add_argument('username', help='Username') add_parser.add_argument('password', help='Password') del_parser = subparser.add_parser('del') del_parser.set_defaults(command='del') del_parser.add_argument('username', help='Username') if __name__ == '__main__': args = parser.parse_args() if args.command == 'add': add_user(args.username, args.password) elif args.command == 'del': del_user(args.username) print(db.query(User).all())
exit(0) if collector.type == 'slido': refresh_slido_with_retry(collector.hash) elif collector.type == 'youtube': print('TODO') time.sleep(5) if __name__ == '__main__': # worker = {} while True: c = db.query(Collector).all() # Start new process for collectors for i in c: if i.id not in worker: worker[i.id] = multiprocessing.Process( target=refresh_collector, args=(i, )) worker[i.id].start() print('Started worker for collector {} type={}'.format( i.id, i.type)) # Remove dead processes ww = list(worker.items()) for i, p in ww: if not p.is_alive(): del worker[i]