程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA綜合教程 >> python如何查看線程id

python如何查看線程id

編輯:JAVA綜合教程

python如何查看線程id


最近使用python多線程程序,發現會耗盡所有的cpu,有必要讓python程序運行在一個cpu上.,但是發現threading.get_ident() 返回一個極大的整數,根本和線程號對不上.
只是使用先獲取系統調用號

  1. #include
  2. #include


  3. int main(void)
  4. {
  5. printf("%d\n", SYS_gettid);
  6. return 0;
  7. }


得到 186

  1. #!/usr/bin/env python

  2. import threading
  3. import os
  4. import ctypes
  5. def cycle_burner():
  6. SYS_gettid = 186
  7. libc = ctypes.cdll.LoadLibrary('libc.so.6')
  8. tid = libc.syscall(SYS_gettid)
  9. print tid
  10. while True:
  11. meh = 84908230489 % 323422

  12. for i in range(3):
  13. thread = threading.Thread(target=cycle_burner)
  14. print "Starting a thread"
  15. thread.start()



運行一切ok

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved