zoukankan      html  css  js  c++  java
  • python3 多线程模拟格式化文本编辑器

    # -*- coding: utf-8 -*-
    from threading import Thread
    
    talk_l = []
    format_l = []
    def talk():
        '''用户输入'''
        while 1:
            inp = input(">>: ").strip()
            if not inp:continue
            talk_l.append(inp)
    
    
    def format():
        '''格式化'''
        while 1:
            if talk_l:
                res = talk_l.pop()
                res = res.upper()
                format_l.append(res)
    
    
    def save():
        '''保存'''
        while 1:
            if format_l:
                with open("db.txt", "a", encoding="utf-8") as f:
                    res = format_l.pop()
                    f.write("%s
    " %res)
    
    
    if __name__ == '__main__':
        '''开启3个线程'''
        t1 = Thread(target=talk)
        t2 = Thread(target=format)
        t3 = Thread(target=save)
        t_l = [t1, t2, t3]
        for t in t_l:
            t.start()
  • 相关阅读:
    NC学习笔记
    NC开发笔记指导
    进度条Demo
    指点
    NC二次开发常用的方法
    java PDF2JPG
    IO笔记
    java Utils
    Lambda 笔记
    gradle记录
  • 原文地址:https://www.cnblogs.com/lilyxiaoyy/p/11025781.html
Copyright © 2011-2022 走看看