VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • python如何下载指定版本TensorFlow

一、python安装与下载依赖
依赖版本

TensorFlow>=2.3.0
Keras  >= 2.4.3
Numpy < 1.19.0
Pandas >= 1.1.0
scikit-learn >= 0.23.2
librosa >=0.8.0
scipy==1.4.1

依赖下载

TensorFlow>=2.3.0 pip3 install tensorflow-cpu==2.3.0 -i https://pypi.douban.com/simple/
Keras >= 2.4.3 pip3 install Keras==2.4.3 -i https://pypi.douban.com/simple/
Pandas >= 1.1.0 pip3 install Pandas==1.1.0 -i https://pypi.douban.com/simple/
scikit-learn >= 0.23.2 pip3 install scikit-learn==0.23.2 -i https://pypi.douban.com/simple/
librosa >=1.19.1 pip3 install librosa==0.8.0 -i https://pypi.douban.com/simple/
scipy==1.4.1 pip3 install scipy==1.4.1 -i https://pypi.douban.com/simple/

安装python3

yum -y install gcc
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
tar -zxvf Python-3.7.3.tgz
mkdir /usr/local/python3
cd Python-3.7.3
./configure --prefix=/usr/local/python3
make && make install
ln -sf /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -sf /usr/local/python3/bin/pip3.7 /usr/bin/pip3

验证

pip3 list
pip3升级

pip3 --default-timeout=10000 install -U pip
pip3 卸载与安装

pip3 install 包名 例如:pip3 install Pandas
pip3 uninstall 包名 例如: pip3 uninstall Pandas

二、mybatis plus 乐观锁配置

import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
 
/**
 * mybatis plus 乐观锁配置
 * @author nick
 */
@EnableTransactionManagement
@Configuration
public class MybatisPlusConfig {
    /**
     *   乐观锁
     */
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor() {
        return new OptimisticLockerInterceptor();
    }
}

三、@Scheduled定时任务升级分布式定时任务

/**
 * DisSchedule切面
 */
@Order(100)
@Aspect
@Slf4j
public class DisScheduleAspect {
 
    public static final String SERVER_NAME = "serverName";
 
    private final IDisScheduleService disScheduleService;
 
    private final String serverName;
 
    public DisScheduleAspect(
        IDisScheduleService disScheduleService,
        Environment environment) {
        Preconditions.checkNotNull(disScheduleService);
        this.disScheduleService = disScheduleService;
        Preconditions.checkNotNull(environment);
        String serverName = environment.getProperty(SERVER_NAME);
        Preconditions.checkArgument(!Strings.isNullOrEmpty(serverName));
        this.serverName = serverName;
    }
 
    /**
     * 方法上有注解SaveLog
     */
    @Pointcut(value = "@annotation(com.citydo.xclouddesk.interceptor.annotation.DisSchedule)")
    public void disScheduleAnnotation() {
    }
 
    @Around(value = "disScheduleAnnotation() && @annotation(disSchedule)")
    public Object disSchedule(ProceedingJoinPoint joinPoint, DisSchedule disSchedule) throws Throwable {
        Preconditions.checkNotNull(disSchedule);
        // 当前时间
        Date curDate = TimeUtil.getCurDate();
        // 获取name
        String name = disSchedule.name();
        if (Strings.isNullOrEmpty(name)) {
            // 方法名
            Signature signature = joinPoint.getSignature();
            name = signature.getName();
        }
        // 时间间隔
        int duration = disSchedule.duration();
        if (duration <= 0) {
            log.error(
                "disSchedule fail, duration {} is less or equal 0, name : {}",
                duration,
                name
            );
            return null;
        }
        // 时间间隔的单位
        TimeUnit unit = disSchedule.unit().getUnit();
        // 转化为毫秒
        long millis = unit.toMillis(duration);
        // 获取当前任务所属的开始时间
        Date taskDate = TimeUtil.getMillisDate(curDate, (int) millis);
        // 当前服务是否属于线上服务
        if (!disScheduleService.serverNameIsValid(serverName)) {
            log.info(
                "disSchedule fail, serverName is invalid, serverName : {} , name : {} , taskDate : {}",
                serverName,
                name,
                TimeUtil.specialFormatToDateStr(taskDate)
            );
            return null;
        }
        if (!disScheduleService.tryGetLock(name, taskDate, serverName)) {
            log.info(
                "Distributed lock not acquired, name : {} , taskDate : {}",
                name,
                TimeUtil.specialFormatToDateStr(taskDate)
            );
            return null;
        }
        // 执行正常的方法逻辑
        return joinPoint.proceed();
    }
}
/**
 * 在方法执行之前,决定当前是否需要执行定时调度任务
 * @author nick
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface DisSchedule {
 
    /**
     * 定时调度任务的名称(默认是方法名)
     */
    String name() default "";
 
    /**
     * 任务的间隔时间
     */
    int duration();
 
    /**
     * duration的时间单位(默认:分钟)
     */
    DisScheduleUnit unit() default DisScheduleUnit.MINUTES;
}
/**
 * 分布式定时调度服务
 * @author nick
 */
public interface IDisScheduleService {
 
    /**
     * 重新加载
     */
    void reload();
 
    /**
     * serverName是否有效
     */
    boolean serverNameIsValid(String serverName);
 
    /**
     * 尝试获取锁
     */
    boolean tryGetLock(String taskName, Date taskDate, String serverName);
 
    /**
     * 添加当前的serverName
     */
    void addServerName(String serverName);
 
    /**
     * 移除当前的serverName
     */
    void removeServerName(String serverName);
}

``

/**
 * redis实现
 */
@Slf4j
@Service
public class DisScheduleRedisServiceImpl implements IDisScheduleService {
 
    public static final String DIS_SCHEDULE_SERVER_NAME = "disScheduleServerName";
 
    private final IRedisManager redisManager;
 
    public DisScheduleRedisServiceImpl(IRedisManager redisManager) {
        Preconditions.checkNotNull(redisManager);
        this.redisManager = redisManager;
    }
 
    @Override
    public void reload() {
        // do nothing
    }
 
    @Override
    public boolean serverNameIsValid(String serverName) {
        try {
            return redisManager.isMember(DIS_SCHEDULE_SERVER_NAME, serverName);
        } catch (Exception e) {
            log.error(
                "DisScheduleRedisServiceImpl-serverNameIsValid fail, serverName : {} , exception : {}",
                serverName,
                e
            );
        }
        return false;
    }
 
    @Override
    public boolean tryGetLock(String taskName, Date taskDate, String serverName) {
        try {
            return redisManager.setNx(
                taskName + "_" + TimeUtil.specialFormatToDateStr(taskDate),
                serverName
            );
        } catch (Exception e) {
            log.error(
                "DisScheduleRedisServiceImpl-tryGetLock fail, taskName : {} , taskDate : {} , serverName : {} , exception : {}",
                taskName,
                TimeUtil.specialFormatToDateStr(taskDate),
                serverName,
                e
            );
        }
 
        return false;
    }
 
    @Override
    public void addServerName(String serverName) {
        Preconditions.checkArgument(!Strings.isNullOrEmpty(serverName));
        redisManager.sAdd(DIS_SCHEDULE_SERVER_NAME, serverName);
    }
 
    @Override
    public void removeServerName(String serverName) {
        Preconditions.checkArgument(!Strings.isNullOrEmpty(serverName));
        redisManager.sRem(DIS_SCHEDULE_SERVER_NAME, serverName);
    }
 
 
//  @DisSchedule(name = "testSchedule", duration = 1, unit = DisScheduleUnit.MINUTES)
//  @Scheduled(cron = "0 0/1 * * * ?")
//  public void testSchedule() {
//  logger.info("输出");
//  }
}
public interface IRedisManager {
 
 
    /**
     * 向set中添加元素
     */
    boolean sAdd(String key, String value);
 
    /**
     * set中是否存在value
     */
    boolean isMember(String key, String value);
 
    /**
     * 移除set中的元素
     */
    void sRem(String key, String value);
 
 
    /**
     * 设置字符串的值(如果不存在的话)
     */
    boolean setNx(String key, String value);
}
复制
public interface IRedisManager {


	/**
	 * 向set中添加元素
	 */
	boolean sAdd(String key, String value);

	/**
	 * set中是否存在value
	 */
	boolean isMember(String key, String value);

	/**
	 * 移除set中的元素
	 */
	void sRem(String key, String value);


	/**
	 * 设置字符串的值(如果不存在的话)
	 */
	boolean setNx(String key, String value);
}
/**
 * 基于jedis实现的redisManager
 */
@Service
public class JedisManagerImpl implements IRedisManager {
 
    @Autowired
    private JedisPoolClient jedisPoolClient;
 
    /**
     * 返回1说明添加成功,返回0说明已经存在
     * @param key
     * @param value
     * @return
     */
    @Override
    public boolean sAdd(String key, String value) {
        Preconditions.checkArgument(!Strings.isNullOrEmpty(key));
        Preconditions.checkArgument(!Strings.isNullOrEmpty(value));
        return jedisPoolClient.sAdd(key, value) == 1L;
    }
 
    @Override
    public boolean isMember(String key, String value) {
        Preconditions.checkArgument(!Strings.isNullOrEmpty(key));
        Preconditions.checkArgument(!Strings.isNullOrEmpty(value));
        return jedisPoolClient.isMember(key, value);
    }
 
    @Override
    public void sRem(String key, String value) {
        Preconditions.checkArgument(!Strings.isNullOrEmpty(key));
        Preconditions.checkArgument(!Strings.isNullOrEmpty(value));
        jedisPoolClient.sRem(key, value);
    }
 
    @Override
    public boolean setNx(String key, String value) {
        Preconditions.checkArgument(!Strings.isNullOrEmpty(key));
        Preconditions.checkArgument(!Strings.isNullOrEmpty(value));
        return jedisPoolClient.setNX(key, value);
    }
}

参考:https://github.com/death00/dis-schedule

四、Multiset与HashMap、Multimap关系

总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

原文链接:https://blog.csdn.net/qq_32447301/article/details/108353508


相关教程