def Dump2(channel_id): global error_map globv.update_logger.info('start record %s' % channel_id) port = dbutil.get_udp_port(channel_id) if port is None: error_map[channel_id] = 'wrong stream' globv.update_logger.error( 'channel %s \'s address don\'t have a port number!' % channel_id) dbutil.set_start(channel_id, False) return channel_path = os.path.join(globv.html_path, channel_id) if not os.path.exists(channel_path): globv.update_logger.info('create path: %s' % channel_path) os.makedirs(channel_path) logger = logutil.getLogger(os.path.join(channel_path, channel_id + '.log'), name=channel_id) try: while True: error_map[channel_id] = "success" logger.debug('%s start record with dump()' % channel_id) res = dump(port, channel_path.encode(), 60) if res != 0: error_map[channel_id] = 'no stream' ldbutil.update_err(channel_id, 'no stream') logger.debug(channel_id + ' stopped by dump()!') globv.update_logger.error('channel %s stopped by dump()!' % channel_id) time.sleep(60 * 5) except Exception as e: logger.exception(e) finally: dbutil.set_start(channel_id, False)
def test_set_start(self): dbutil.set_start(self.channel_id, True) is_start = dbutil.is_start(self.channel_id) self.assertEqual(is_start, True) dbutil.set_start(self.channel_id, False) is_start = dbutil.is_start(self.channel_id) self.assertEqual(is_start, False)
def kill(channel_id): global channel_map try: if channel_id in channel_map: process = channel_map[channel_id] process.terminate() globv.update_logger.info('kill ' + channel_id) else: raise ValueError('channel_id(%s) to be killed is not exist!' % channel_id) except Exception as e: globv.update_logger.exception(e) finally: error_map[channel_id] = 'killed' dbutil.set_start(channel_id, False) if channel_id in channel_map: channel_map.pop(channel_id) globv.update_logger.info('kill ' + channel_id + ' done.')
def start_channel(channel_id): global channel_map # if dbutil.is_start(channel_id): # return if channel_id in channel_map: if channel_map[channel_id].is_alive(): return dbutil.set_start(channel_id, True) error_map[channel_id] = "success" ldbutil.update_err(channel_id, 'success') process = multiprocessing.Process(name=channel_id, target=Dump2, args=(channel_id, )) process.daemon = True process.start() globv.update_logger.info('start %s process done' % channel_id) channel_map[channel_id] = process epg.update(channel_id)
def kill(channel_id): dbutil.set_start(channel_id, False) pass