首页 > 编程语言 > 详细

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

时间:2019-06-14 23:09:14      阅读:114      评论:0      收藏:0      [点我收藏+]
# -*- 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 多线程模拟格式化文本编辑器

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!