码迷,mamicode.com
首页 > 编程语言 > 详细

python3 多线程模拟格式化文本编辑器

时间:2019-06-14 23:59:31      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:class   continue   enc   线程   input   div   bsp   输入   threading   

# -*- 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\n" %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()

 

python3 多线程模拟格式化文本编辑器

标签:class   continue   enc   线程   input   div   bsp   输入   threading   

原文地址:https://www.cnblogs.com/lilyxiaoyy/p/11025781.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!