栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

《Python语言程序设计》王恺 王志 李涛 机械工业出版社 第8章 多线程与多进程 课后习题答案【强烈推荐】

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

《Python语言程序设计》王恺 王志 李涛 机械工业出版社 第8章 多线程与多进程 课后习题答案【强烈推荐】

点个吧,秋梨膏!!!!!,建议收藏一波

第8章 多线程与多进程
  1. 线程是操作系统进行 运算调度 的最小单位。

  2. 当一个进程被创建时,操作系统会自动为进程建立一个线程,通常称为 主线程 。

  3. 进程是一个正在执行中的应用程序 所有资源 的集合。

  4. 使用创建线程来执行一个函数,可以 不中断 当前函数的执行,实现多个函数并行执行,提高程序的执行效率。

  5. 将一个线程的 daemon 属性设置为True,则该线程为守护线程。

  6. 一个锁在locked和unlocked两种状态间切换,刚创建的Lock对象默认是 unlocked 状态。

  7. 多线程同步时如果一个资源对应着多个锁,可能会发生 死锁 问题,在使用多个锁时要认真检查。

  8. 在Python中进行多线程编程,通常使用的高层次多线程编程模块是( B )。
    A. thread
    B. threading
    C. multithread
    D. multithreading

  9. threading模块中用于判断线程是否活动的方法是( D )。
    A. start
    B. isStart
    C. alive
    D. isAlive

  10. 在Python中进行多进程编程,通常使用的编程模块是( D )。
    A. process
    B. processing
    C. multiprocess
    D. multiprocessing

  11. 写出下面程序的运行结果。
    import time, threading
    def func(x):
    print("%s线程正在运行!" % threading.current_thread().name)
    time.sleep(x)
    print("%s线程运行结束!" % threading.current_thread().name)
    if name == “main”:
    print("%s线程正在运行!" % threading.current_thread().name)
    t_1 = threading.Thread(target=func, args=(5,))
    t_2 = threading.Thread(target=func, args=(3,))
    t_1.start()
    t_2.start()
    运行结果:
    MainThread线程正在运行!
    Thread-1线程正在运行!
    Thread-2线程正在运行!
    Thread-2线程运行结束!
    Thread-1线程运行结束!

  12. 下面代码自定义了线程类my_thread,请将程序填写完整。
    import time, threading
    class my_thread( ):
    def init(self, x):
    threading.Thread. (self)
    self.x = x
    def run(self):
    print("%s线程正在运行!" %
    threading.current_thread().name)
    time.sleep(self.x)
    print("%s线程运行结束!" % threading.current_thread().name)
    参考答案:
    threading.Thread
    init

点个吧,秋梨膏!!!!!,建议收藏一波

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/354775.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号