How to apply the Python main thread

Source: Internet
Author: User

The main Python thread is a conversion method that we often use. But how can we better use this programming language? Next, let's take a look at this article in detail. In the main Python thread or child thread, the following processing is used to call Python functions.

 
 
  1. {
  2. Class PyThreadStateLock PyThreadLock;
  3. // Call python API function processing
  4. ......
  5. }

Haha, it's very easy to see.

There are also two macros related to the global lock, Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS. These two macros are used to temporarily release the global lock before calling the C function for a long time, and then obtain the global lock again to avoid blocking other python threads to continue running. These two macros can be called in this way.

 
 
  1. {
  2. Class PyThreadStateLock PyThreadLock;
  3. // Call python API function processing
  4. ......
  5. Py_BEGIN_ALLOW_THREADS
  6. // Call the C function that requires a long time
  7. ......
  8. Py_END_ALLOW_THREADS
  9. // Call python API function processing
  10. ......
  11. }

Possible Errors and Solutions

A. a link problem occurs in debug mode in vs 200x.

 
 
  1. extmodule.obj : error LNK2019: unresolved external 
    symbol __imp___Py_Dealloc referenced in function _
    PySwigObject_format  
  2. extmodule.obj : error LNK2019: unresolved external 
    symbol __imp___Py_NegativeRefcount referenced in function
     _PySwigObject_format  
  3. extmodule.obj : error LNK2001: unresolved external symbol
     __imp___Py_RefTotal  
  4. extmodule.obj : error LNK2019: unresolved external symbol
     __imp___PyObject_DebugFree referenced in function 
    _PySwigObject_dealloc  
  5. extmodule.obj : error LNK2019: unresolved external symbol __imp
    ___PyObject_DebugMalloc referenced in function _PySwigObject_New  
  6. extmodule.obj : error LNK2019: unresolved external symbol __imp
    __Py_InitModule4TraceRefs referenced in function _init_extmodule 

It is mainly caused by Py_DEBUG/Py_TRACE_REFS. Modify the pyconfig. h and object. h files under Python \ include. The above is a description of the main Python thread.

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.