如标题所示,即使在不同的进程中,对threading.currentThread().ident的不同调用也会返回34382823872. (使用Python 3.1和FreeBSD)python线程是否是FreeBSD的问题?解决方法:您是否正在REPL中对此进行测试?还是在实际...

如标题所示,即使在不同的进程中,对threading.currentThread().ident的不同调用也会返回34382823872. (使用Python 3.1和FreeBSD)
python线程是否是FreeBSD的问题?
解决方法:
您是否正在REPL中对此进行测试?还是在实际程序中?我问是因为当我使用REPL运行以下代码时,得到的结果是相同的,但是当我运行与脚本相同的代码时,线程具有不同的标识符.
import threading
def thid():
print threading.currentThread().ident
t1 = threading.Thread(target=thid)
t2 = threading.Thread(target=thid)
t1.start()
t2.start()
t1.join()
t2.join()
REPL输出:
>>> t1.start()
4301111296
>>> t2.start()
4301111296
脚本输出:
me@mine:~ $python th.py
4300935168
4302835712
我怀疑这是预期的行为;以下是来自threading文档的信息:
The ‘thread identifier’ of this thread or None if the thread has not been started. This is a nonzero integer. See the thread.get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created.
此外,我在REPL中修改了thid,如下所示:
>>> def thid():
... print threading.currentThread().ident
... sleep(10)
当我在调用t1.start()的10秒内调用t2.start()时,它们具有不同的ID,但是如果我等待10秒钟以上,则它们具有相同的ID.
如果要区分不同的线程,只需调用id(threading.currentThread()). Python ID始终是不同的.
本文标题为:Python和FreeBSD:即使在不同的进程中,threading.currentThread().ident也返回相同的值


基础教程推荐
- python-在子目录nginx uwsgi上提供Flask应用 2023-11-11
- python-无法在Windows 7中删除测试文件夹 2023-11-12
- centos7安装python3 以及tab补全功能 2023-09-03
- python模拟进程状态 2023-11-12
- Pytorch中的Tensorboard与Transforms搭配使用 2023-08-11
- python中的bisect模块与二分查找详情 2022-10-20
- Python lambda 匿名函数优点和局限性深度总 2022-08-30
- Python list sort方法的具体使用 2023-08-04
- Python requirements.txt安装用法介绍 2023-10-08
- python-3.x-使用gunicorn nginx的服务烧瓶应用程序显示404 [ec2] 2023-11-11