How to view the thread id in python

Source: Internet
Author: User

How to view the thread id in python
I recently used a python multi-threaded program and found that it would consume all the CPUs. It is necessary to let python program run on one cpu ., however, threading is found. get_ident () returns a very large integer, which cannot be matched with the thread number.
You only need to obtain the system call number first.

 
 
  1. #include
  2. #include


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


Get 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()



Run all OK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.