Thread processing method, task processing method, device and equipment

By establishing an independent execution environment for each thread, the problem of multi-threaded serial execution in CPython is solved, and multi-core parallel processing is realized, which improves task processing efficiency and performance.

CN113296939BActive Publication Date: 2025-07-04ALIBABA INNOVATION PRIVATE LIMITED
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202110326778.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-03-26
Publication Date
2025-07-04
Estimated Expiration
2041-03-26

AI Technical Summary

Technical Problem

Because CPython was born in the era of single-core CPUs, it did not consider the problem of multi-core concurrency, which resulted in the execution of multi-threads, and could not utilize the CPU's multi-core capabilities, which reduced the code execution efficiency.

Method used

By establishing an independent execution environment for each thread, reducing the use of locks, using Python tools to remove global interpreter locks, establishing a thread's private execution environment, and implementing parallel execution of threads.

Benefits of technology

It effectively reduces the use of locks, reduces memory overhead, improves the quality and efficiency of task processing, and improves the performance and practicality of thread processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113296939B_ABST
    Figure CN113296939B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a thread processing method, a task processing method, an apparatus and a device. The thread processing method includes: obtaining a thread to be processed; establishing an execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other; and processing the thread in the execution environment. The technical solution provided by the present application obtains a thread to be processed, and then establishes an execution environment corresponding to the thread, so that the execution environments corresponding to each thread are independent of each other, so that the thread can be processed in the execution environment, effectively realizing that multiple processes can process corresponding tasks in their respective corresponding execution environments, not only effectively reducing the use of a large number of locks, reducing memory overhead, but also improving the quality and efficiency of task processing, which is beneficial to improving data processing performance, further improving the practicability of the thread processing method, and facilitating market promotion and application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of thread technology, and particularly to a thread processing method, a task processing method, a device, and a device. Background Art

[0002] In recent years, with the continuous development of artificial intelligence technology, artificial intelligence has moved from academic research to engineering field practice. As the only language in the field of artificial intelligence, the computer programming language Python is usually used as the common programming language for algorithm tasks. Since CPython has a dominant position in the Python interpreter ecosystem, currently, a trimmed version of CPython is used as the mobile execution container for edge computing, where CPython is a Python tool implemented using the C language.

[0003] Among them, since the CPython kernel code was born in the era of single-core CPUs, the issue of multi-core concurrent execution was not considered during implementation. With the popularization and implementation of multi-core concurrent application scenarios, the Global Interpreter Lock (GIL for short) is currently often used to solve the synchronization problem of multi-threads. However, in the CPython execution engine, if a thread needs to execute Python bytecode, it must first obtain the GIL. Although the above implementation method solves the problem of multi-threaded concurrency, it also directly causes multi-threads to be executed in a serial manner, unable to utilize the multi-core capabilities of the CPU, and at the same time reducing the code execution efficiency. Summary of the Invention

[0004] Embodiments of this application provide a thread processing method, a task processing method, a device, and a device, which effectively reduce the use of locks, greatly improve the execution performance of threads, and are also beneficial to improving the code execution efficiency.

[0005] In a first aspect, embodiments of this application provide a thread processing method, including:

[0006] Obtain the thread to be processed;

[0007] Establish an execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other;

[0008] Process the thread in the execution environment.

[0009] In a second aspect, embodiments of this application provide a thread processing device, including:

[0010] A first acquisition module, configured to acquire the thread to be processed;

[0011] A first establishment module, configured to establish an execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other;

[0012] A first processing module, configured to process the thread in the execution environment.

[0013] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory and a processor; wherein, the memory is used to store one or more computer instructions, and when the one or more computer instructions are executed by the processor, the thread processing method shown in the above first aspect is implemented.

[0014] In a fourth aspect, an embodiment of the present invention provides a computer storage medium, configured to store a computer program, and when the computer program is executed by a computer, the thread processing method shown in the above first aspect is implemented.

[0015] In a fifth aspect, an embodiment of the present application provides a thread processing method, including:

[0016] Obtain a thread to be processed and an execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other;

[0017] In the execution environment, process the thread.

[0018] In a sixth aspect, an embodiment of the present application provides a thread processing device, including:

[0019] A second acquisition module, configured to acquire a thread to be processed and an execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other;

[0020] A second processing module, configured to process the thread in the execution environment.

[0021] In a seventh aspect, an embodiment of the present application provides an electronic device, including: a memory and a processor; wherein, the memory is used to store one or more computer instructions, and when the one or more computer instructions are executed by the processor, the thread processing method shown in the above fifth aspect is implemented.

[0022] In an eighth aspect, an embodiment of the present invention provides a computer storage medium, configured to store a computer program, and when the computer program is executed by a computer, the thread processing method shown in the above fifth aspect is implemented.

[0023] In a ninth aspect, an embodiment of the present invention provides a thread processing method, including:

[0024] Obtain at least two threads to be processed;

[0025] Determine the execution environment corresponding to each of the at least two threads, where the execution environments corresponding to each of the at least two threads are independent of each other;

[0026] Based on the execution environments corresponding to each of the at least two threads, perform synchronization processing or asynchronous processing on the at least two threads.

[0027] In a tenth aspect, an embodiment of the present invention provides a thread processing device, including:

[0028] A third acquisition module, configured to acquire at least two threads to be processed;

[0029] A third determination module, configured to determine the execution environment corresponding to each of the at least two threads, where the execution environments corresponding to each of the at least two threads are independent of each other;

[0030] A third processing module, configured to perform synchronization processing or asynchronous processing on the at least two threads based on the execution environments corresponding to each of the at least two threads.

[0031] In an eleventh aspect, an embodiment of the present application provides an electronic device, including: a memory and a processor; wherein, the memory is used to store one or more computer instructions, and when the one or more computer instructions are executed by the processor, the thread processing method shown in the above ninth aspect is implemented.

[0032] In a twelfth aspect, an embodiment of the present invention provides a computer storage medium, used to store a computer program, and when the computer program is executed by a computer, the thread processing method shown in the above ninth aspect is implemented.

[0033] In a thirteenth aspect, an embodiment of the present invention provides a task processing method, including:

[0034] Acquire a task to be processed;

[0035] Generate a process corresponding to the task to be processed and at least one thread located in the process;

[0036] Establish the execution environment corresponding to each of the at least one thread, where the execution environments corresponding to each thread are independent of each other;

[0037] Based on the execution environments corresponding to each of the at least one thread, perform synchronization or asynchronous processing on the at least one thread to obtain a processing result corresponding to the task to be processed.

[0038] In a fourteenth aspect, an embodiment of the present invention provides a task processing device, including:

[0039] A fourth acquisition module, configured to acquire a task to be processed;

[0040] A fourth generation module, configured to generate a process corresponding to the to-be-processed task and at least one thread located in the process;

[0041] A fourth establishment module, configured to establish an execution environment corresponding to each of the at least one thread, wherein the execution environments corresponding to the respective threads are independent of each other;

[0042] A fourth processing module, configured to synchronously or asynchronously process the at least one thread based on the execution environment corresponding to each of the at least one thread, and obtain a processing result corresponding to the to-be-processed task.

[0043] In a fifteenth aspect, an embodiment of the present application provides an electronic device, including: a memory and a processor; wherein, the memory is configured to store one or more computer instructions, and when the one or more computer instructions are executed by the processor, the task processing method shown in the above thirteenth aspect is implemented.

[0044] In a sixteenth aspect, an embodiment of the present invention provides a computer storage medium, configured to store a computer program, and when the computer program is executed by a computer, the task processing method shown in the above thirteenth aspect is implemented.

[0045] The technical solution provided by the embodiment of the present application obtains the to-be-processed thread, and then establishes an execution environment corresponding to the thread, so that the execution environments corresponding to the respective threads are independent of each other, so that the thread can be processed in the execution environment, effectively realizing that multiple processes can process corresponding tasks in their respective corresponding execution environments, not only effectively reducing the use of a large number of locks, reducing the memory overhead, but also improving the quality and efficiency of task processing, which is beneficial to improving the performance of thread processing, further improving the practicability of the thread processing method, and facilitating the market promotion and application. Description of the Drawings

[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained according to these drawings without creative efforts.

[0047] Figure 1 It is a signaling interaction diagram of a thread processing method provided in the related art of the present application;

[0048] Figure 2 It is a schematic diagram of an application scenario of a thread processing method provided in the related art of the present application in a multi-process scenario;

[0049] Figure 3 Flow diagram of a thread processing method provided by an embodiment of the present application;

[0050] Figure 4 Principle diagram of the thread processing method provided by an embodiment of the present application;

[0051] Figure 5 Flow diagram of establishing an execution environment corresponding to the thread provided by an embodiment of the present application;

[0052] Figure 6 Flow diagram of thread isolation for the execution environment provided by an embodiment of the present application;

[0053] Figure 7 Flow diagram of another thread processing method provided by an embodiment of the present application;

[0054] Figure 8 Flow diagram of yet another thread processing method provided by an embodiment of the present application;

[0055] Figure 9 Flow diagram of a thread processing method provided by an application embodiment of the present application;

[0056] Figure 10 Structure diagram of a thread processing device provided by an embodiment of the present application;

[0057] Figure 11 For Figure 10 Structure diagram of the electronic device corresponding to the thread processing device shown;

[0058] Figure 12 Structure diagram of another thread processing device provided by an embodiment of the present application;

[0059] Figure 13 For Figure 12 Structure diagram of the electronic device corresponding to the thread processing device shown;

[0060] Figure 14 Structure diagram of yet another thread processing device provided by an embodiment of the present application;

[0061] Figure 15 For Figure 14 Structure diagram of the electronic device corresponding to the thread processing device shown;

[0062] Figure 16 Flow diagram of a task processing method provided by an application embodiment of the present application;

[0063] Figure 17 Structure diagram of a task processing device provided by an embodiment of the present application;

[0064] Figure 18 For Figure 17 the schematic structural diagram of the electronic device corresponding to the task processing device shown. Specific embodiments

[0065] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Apparently, the described embodiments are some but not all of the embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present application without making creative efforts fall within the scope of protection of the present application.

[0066] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments and are not intended to limit the present application. The singular forms "a", "the", and "said" used in the embodiments of the present application and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. "Plural" generally includes at least two, but does not exclude the case of including at least one.

[0067] It should be understood that the term " / and" used herein is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the character " / " herein generally represents an "or" relationship between the preceding and following associated objects.

[0068] Depending on the context, the words "if" and "when" used herein can be interpreted as "when" or "when...", or "in response to determining" or "in response to detecting". Similarly, depending on the context, the phrase "if determined" or "if detecting (stated condition or event)" can be interpreted as "when determined" or "in response to determining" or "when detecting (stated condition or event)" or "in response to detecting (stated condition or event)".

[0069] It should also be noted that the term "including", "comprising", or any other variant thereof is intended to cover non-exclusive inclusion, so that a commodity or system including a series of elements not only includes those elements but also includes other elements not explicitly listed, or also includes elements inherent to such a commodity or system. Without further limitation, the element defined by the statement "including one..." does not exclude the existence of another identical element in the commodity or system including the said element.

[0070] In addition, the sequence of steps in the following method embodiments is only an example and is not strictly limited.

[0071] To facilitate the understanding of the technical solutions provided by the embodiments of the present application by those skilled in the art, the related technologies are described below:

[0072] Since the CPython kernel code was born in the era of single-core CPUs, the issue of multi-core concurrent execution was not considered during its implementation. With the popularization and implementation of multi-core concurrent application scenarios, the Global Interpreter Lock (GIL for short) is currently often used to solve the synchronization problem of multi-threading. However, in the execution engine of CPython, if a thread needs to execute Python bytecode, it must first obtain the GIL. Although the above implementation method solves the problem of multi-threaded concurrency, it also directly causes multi-threads to be executed serially, unable to utilize the multi-core capabilities of the CPU, and at the same time reducing the code execution efficiency.

[0073] As Figure 1 shown, Thread 1 initially has the GIL. Therefore, Thread 1 obtains the permission to execute bytecode. During the execution of bytecode by Thread 1, the GIL is released due to active reasons (the calling code actively releases the GIL) or passive reasons (the time slice expires). Then, Thread 1 can compete for the GIL again with other threads (Thread 2 and Thread 3). Suppose that after Thread 3 competes for the GIL, Thread 3 obtains the permission to execute Python bytecode. At this time, Thread 1 and Thread 2 are suspended and wait to execute after obtaining the GIL permission next time. In this technical solution, the global GIL solves the problem of Python multi-threaded concurrency. However, this implementation method also directly causes CPython to execute multi-threads serially and unable to utilize the multi-core capabilities of modern CPUs.

[0074] When applying the above implementation method to the application side, in application scenarios where there are a large number of multi-tasks executed in parallel at the same time point and it is desired to complete within a limited time (100 ms), for example: when returning to the details page, based on the browsing behavior records of the user on the details page, the preference information of the user for the commodity is judged, and then the commodity display, benefit distribution, advertisement display, etc. on the page after return are determined. At this time, if multiple tasks are executed serially, it is possible that when the user returns to the previous page, the interested commodities have not been rearranged to the recommended commodity page in time. In this way, it is easy to miss the opportunity to recommend interested commodities, thereby leading to a decrease in turnover. Generally speaking, the GIL has become the main bottleneck restricting the computing performance of the terminal. Therefore, solving the related problems of the GIL existing in Python is an issue that has to be faced.

[0075] To solve the above problems, related technologies provide a thread processing method with fine-grained locks. Since the GIL is a global state lock and one process corresponds to one GIL, its protection granularity is very large. Therefore, to avoid the problems caused by the global state lock, a finer-grained lock can be used to replace the GIL lock. That is, for the memory data that needs to be operated on in a thread, code-level locks can be used to perform lock protection operations on the above-mentioned memory data; for the memory data that does not need to be operated on in a thread, lock protection operations can be omitted. However, in the application scenario of a single thread, the execution performance is halved.

[0076] When applying the above implementation to the application scenario of multiple processes, refer to the attached Figure 2 As shown, one process in the figure can correspond to one interpreter, and one process can include 3 thread tasks. When a certain thread task obtains the GIL, this thread task can execute bytecode based on the GIL, and the other two thread tasks are suspended. When applied to the application scenario of multiple processes, it can include multiple parallel processes, and each process can include 3 thread tasks. When a certain thread task in a certain process obtains the GIL, this thread task can execute bytecode based on the GIL, and the other two thread tasks in the process are suspended, thus effectively realizing the support for multiple process tasks. Users can use multiple processes to execute different tasks in different processes, thereby improving the quality and efficiency of task execution. However, for a single process, there is still a problem that the tasks in the thread are executed serially and the multi-core capabilities of modern CPUs cannot be utilized.

[0077] To solve the above technical problems, this embodiment provides a thread processing method, device, and equipment. The thread processing method obtains the thread to be processed, and then establishes an execution environment corresponding to the thread. In this way, the execution environments corresponding to each thread are independent of each other, so that the thread can be processed in the execution environment. This effectively realizes that multiple processes can process corresponding tasks in their respective corresponding execution environments, not only effectively reducing the use of a large number of locks, reducing memory overhead, but also improving the quality and efficiency of task processing, which is beneficial to improving the performance of thread processing.

[0078] The following specifically describes the thread processing method, device, and equipment provided by each embodiment of the present application through an exemplary application scenario.

[0079] Figure 3 It is a schematic flowchart of a thread processing method provided by an embodiment of the present application; Figure 4 It is a schematic diagram of the principle of the thread processing method provided by an embodiment of the present application; refer to the attached Figures 3 - 4As shown in the figure, this embodiment provides a thread processing method. The execution subject of this method can be a thread processing device. It can be understood that the thread processing device can be implemented as software, or a combination of software and hardware. Specifically, the thread processing method can include:

[0080] Step S301: Obtain the thread to be processed.

[0081] Step S302: Establish an execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other.

[0082] Step S303: Process the thread in the execution environment.

[0083] The following is a detailed description of each of the above steps:

[0084] Step S301: Obtain the thread to be processed.

[0085] Among them, the thread to be processed refers to the thread that needs to perform data processing operations. The number of threads to be processed can be one or more. When the number of threads to be processed is multiple, synchronous or asynchronous processing operations can be performed on multiple threads. In addition, this embodiment does not limit the specific method of obtaining the thread. Those skilled in the art can set it according to specific application scenarios or application requirements. For example: The thread to be processed can be stored in a preset area, and the thread to be processed can be obtained through a preset call instruction. Or, the thread to be processed can be obtained through a code editing tool. At this time, obtaining the thread to be processed can include: obtaining code instructions; based on the code instructions, determining the thread to be processed.

[0086] Specifically, a code editing tool can be set on the thread processing device. The code editing tool can be a Python tool implemented in C language. When performing operations on the thread, the operation interface of the code editing tool for implementing code editing operations can be displayed. The user can input execution operations through the operation interface, so that the thread processing device can obtain the code instructions corresponding to the execution operations. After obtaining the code instructions, the code instructions can be analyzed and processed, so that the thread to be processed can be obtained.

[0087] Of course, those skilled in the art can also use other methods to obtain the thread to be processed, as long as the stable and reliable acquisition of the thread to be processed can be ensured, which will not be elaborated here.

[0088] Step S302: Establish an execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other.

[0089] Among them, after obtaining the thread to be processed, an execution environment corresponding to the thread can be established for each thread, and the thread environments corresponding to the respective threads are independent of each other. For example, referring to the attached Figure 4 As shown, the threads to be processed include Thread 1 and Thread 2. Thread 1 corresponds to Task 1 and Task 3 to be processed, and Thread 2 corresponds to Task 2 to be processed. After obtaining the above-mentioned Thread 1 and Thread 2 to be processed, an execution environment 1 corresponding to Thread 1 and an execution environment 2 corresponding to Thread 2 can be established respectively. It can be understood that the above-mentioned Execution Environment 1 and Execution Environment 2 are independent of each other. The execution environment corresponding to the thread may include running-related data corresponding to the thread. The running-related data includes at least one of the following: supported language types, static data, global data, built-in modules, external modules. This facilitates processing the tasks included in Thread 1 based on Execution Environment 1 and processing the tasks included in Thread 2 based on Execution Environment 2.

[0090] Step S303: Process the thread in the execution environment.

[0091] Among them, after establishing the execution environment corresponding to the thread, the thread can be processed in the execution environment. It can be understood that the same execution environment can correspond to one or more tasks to be processed included in the same thread. When there are multiple tasks corresponding to the same execution environment, the multiple tasks can be processed sequentially in the execution environment.

[0092] In addition, the specific implementation manner of processing the thread in the execution environment in this embodiment is not limited, and those skilled in the art can set it according to specific application scenarios or application requirements. In some examples, processing the thread in the execution environment may include: generating an object corresponding to the task included in the thread in the execution environment; processing the object based on the task included in the thread.

[0093] Specifically, in order to be able to process the thread in the execution environment, an object corresponding to the task included in the thread can be generated first in the execution environment. It can be understood that different thread tasks can generate different objects. After generating the object corresponding to the task included in the thread, the object can be processed in the execution environment based on the task included in the thread, thereby effectively realizing stable processing operations of the thread in the execution environment.

[0094] The thread processing method provided in this embodiment obtains the thread to be processed, and then establishes an execution environment corresponding to the thread. In this way, the execution environments corresponding to each thread are independent of each other, so that the thread can be processed in the execution environment. This effectively enables multiple processes to process corresponding tasks in their respective corresponding execution environments, not only effectively reducing the use of a large number of locks, reducing memory overhead, but also improving the quality and efficiency of task processing. This is conducive to improving the performance of thread processing, further enhancing the practicality of this thread processing method, and facilitating market promotion and application.

[0095] Figure 5 It is a schematic flowchart of establishing an execution environment corresponding to a thread provided by an embodiment of this application; on the basis of the above embodiment, refer to the attached Figure 5 As shown, this embodiment provides an implementation manner of establishing an execution environment corresponding to a thread. Specifically, the establishment of an execution environment corresponding to a thread in this embodiment may include:

[0096] Step S501: Obtain a Python tool for establishing an execution environment.

[0097] Among them, in order to be able to establish an execution environment corresponding to a thread, a tool for establishing an execution environment can be obtained. In some instances, the above tool can be a Python tool. It can be understood that the tool for establishing an execution environment is not limited to the above-described Python tool, and those skilled in the art can adjust and select the tool based on specific application scenarios or application requirements. For example: the above tool can be a NOTEPAD++ tool, a VIM tool, an Emacs tool, etc. When the above tool is a Python tool, obtaining the Python tool for establishing an execution environment may include: obtaining the original Python tool; removing the built-in thread module for establishing a global exclusive lock included in the original Python tool to obtain the Python tool.

[0098] Specifically, a raw Python tool for code editing operations is preset. This raw Python tool can be stored in a preset area, and the raw Python tool can be called and obtained by accessing the preset area. After obtaining the raw Python tool, the Python tool can be analyzed. Since the raw Python tool includes a built-in thread module for establishing a global exclusive lock, in this embodiment, in order to ensure that no global exclusive lock related to the thread is generated during the process of using the Python tool to process the thread, the built-in thread module included in the raw Python tool can be removed, so that a Python tool without the built-in thread module can be obtained. This Python is used to establish an execution environment and does not establish a global exclusive lock related to the thread.

[0099] Of course, those skilled in the art can also use other methods to obtain the Python tool for establishing the execution environment, as long as the accuracy and reliability of obtaining the Python tool can be ensured, which will not be elaborated here.

[0100] Step S502: Use the Python tool to establish an execution environment.

[0101] After obtaining the Python tool, an execution environment corresponding to the thread can be established using the Python tool. In some instances, establishing an execution environment using the Python tool may include: obtaining operation-related data corresponding to the thread; based on the operation-related data, using the Python tool to establish an execution environment.

[0102] Specifically, after obtaining the thread, operation-related data corresponding to the thread can be determined. The operation-related data may include at least one of the following: supported language types (such as int data type, double data type, float data type, char data type, etc.), static data, global data, built-in modules, external modules. Specifically, the above-mentioned operation-related data can be stored in a preset area, and the operation-related data corresponding to the thread can be obtained by accessing the preset area. After obtaining the operation-related data, an execution environment can be established based on the operation-related data and using the Python tool, thus effectively ensuring the accuracy and reliability of establishing the execution environment.

[0103] In this embodiment, by obtaining the Python tool for establishing the execution environment and then using the Python tool to establish the execution environment, the accuracy and reliability of establishing the execution environment are effectively ensured, which further improves the quality and efficiency of analyzing and processing the thread based on the execution environment.

[0104] In some instances, after establishing an execution environment using Python tools, the method in this embodiment may further include: associatively storing a thread with the corresponding execution environment.

[0105] Among them, after obtaining a thread and the execution environment corresponding to the thread, in order to facilitate the analysis and processing of the corresponding thread based on the execution environment, the thread can be associatively stored with the corresponding execution environment. For example, the threads to be processed include Thread 1, Thread 2, and Thread 3. Thread 1 corresponds to Execution Environment 1, Thread 2 corresponds to Execution Environment 2, and Thread 3 corresponds to Execution Environment 3. In order to facilitate the analysis and processing of Thread 1, Thread 2, and Thread 3, after obtaining the execution environments corresponding to the above threads, the threads and the corresponding execution environments can be associatively stored. For example: associatively store Thread 1 with Execution Environment 1, associatively store Thread 2 with Execution Environment 2, and associatively store Thread 3 with Execution Environment 3, and then it is convenient to perform corresponding processing operations on the threads based on the created execution environment.

[0106] In some instances, the method in this embodiment may further include: performing thread isolation on the execution environment.

[0107] Among them, in order to ensure that each thread performs stable analysis and processing operations in its corresponding execution environment, after obtaining the execution environment, thread isolation operations can be performed on the execution environment.

[0108] In some instances, referring to the attached Figure 6 As shown, performing thread isolation on the execution environment may include:

[0109] Step S601: Obtain the global data and static data included in the execution environment.

[0110] Step S602: Perform isolation processing on the global data and static data.

[0111] Among them, the execution environment may include global data and static data. In order to perform thread isolation operations on the execution environment, the global data and static data included in the execution environment can be obtained, and then isolation processing can be performed on the global data and static data, thereby effectively realizing thread isolation operations on the data that needs to be protected in the execution environment, and further ensuring the stable reliability of thread isolation for the execution environment.

[0112] In this embodiment, by obtaining the global data and static data included in the execution environment and then performing isolation processing on the global data and static data, it effectively realizes thread isolation operations on the data that needs to be protected in the execution environment, and further ensures the stable reliability of thread isolation for the execution environment.

[0113] In some examples, after processing a thread in an execution environment, the method in this embodiment may further include: destroying the execution environment.

[0114] Among them, in order to reduce the data processing resources and data space occupied by the execution environment, after analyzing and processing the thread based on the execution environment, the execution environment corresponding to the thread may be destroyed. For example, the threads to be processed include Thread 1 and Thread 2, Thread 1 corresponds to Execution Environment 1, and Thread 2 corresponds to Execution Environment 2. After analyzing and processing Thread 1 based on Execution Environment 1, Execution Environment 1 can be destroyed; when Thread 2 has not been analyzed and processed, the execution environment may not be destroyed until Thread 2 is analyzed and processed, and then Execution Environment 2 can be destroyed. This can effectively reduce the data processing resources and data space occupied by the execution environment, further improving the practicability of the method and facilitating market promotion and application.

[0115] In other examples, after destroying the execution environment, after obtaining the thread to be processed, an execution environment corresponding to the thread is established again.

[0116] Specifically, after destroying the execution environment, if a thread to be processed is obtained, an execution environment corresponding to the above thread can be created again based on the obtained thread to be processed, so as to analyze and process the thread based on the above execution environment, which can effectively improve the quality and efficiency of thread processing.

[0117] Figure 7 It is a schematic flowchart of another thread processing method provided by an embodiment of the present application; referring to the appendix Figure 7 As shown, this embodiment provides another thread processing method. The execution subject of this method may be another thread processing device. It can be understood that this thread processing device can be implemented as software, or a combination of software and hardware. Specifically, this thread processing method may include:

[0118] Step S701: Obtain the thread to be processed and the execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other.

[0119] Step S702: Process the thread in the execution environment.

[0120] The above steps will be described in detail below:

[0121] Step S701: Obtain the thread to be processed and the execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other.

[0122] Among them, the specific acquisition method and implementation effect of the thread to be processed in this embodiment are similar to those of the thread to be processed obtained in step S301 above. For details, please refer to the above description and will not be elaborated here.

[0123] Different from the Figure 3 embodiment shown above, Figure 3 the specific implementation of the embodiment shown above is as follows: after obtaining the thread to be processed, an execution environment corresponding to the thread can be established based on the thread to be processed. In this embodiment, the execution environment corresponding to the thread is pre-established, and there is no need to establish an execution environment corresponding to the thread based on the thread processing request. The pre-established execution environment corresponding to the thread can be stored in a preset area, and the execution environment corresponding to the thread can be obtained by accessing the preset area.

[0124] Step S702: Process the thread in the execution environment.

[0125] Among them, the specific acquisition method and implementation effect of the above steps in this embodiment are similar to those of step S303 above. For details, please refer to the above description and will not be elaborated here.

[0126] The thread processing method provided in this embodiment obtains the thread to be processed and the execution environment corresponding to the thread. Moreover, the execution environments corresponding to each thread are independent of each other. Then, the thread is processed in the execution environment, so that the thread can be processed in the execution environment. In this way, it effectively realizes that multiple processes can process corresponding tasks in their respective corresponding execution environments, not only effectively reducing the use of a large number of locks, reducing memory overhead, but also improving the quality and efficiency of task processing. This is conducive to improving the performance of thread processing, further improving the practicability of the thread processing method, and facilitating market promotion and application.

[0127] Figure 8 is a schematic flowchart of another thread processing method provided by an embodiment of the present application; referring to the appendix Figure 8 shown, this embodiment provides another thread processing method. The execution subject of this method can be another thread processing device. It can be understood that this thread processing device can be implemented as software, or a combination of software and hardware. Specifically, this thread processing method may include:

[0128] Step S801: Obtain at least two threads to be processed.

[0129] Step S802: Determine the execution environments corresponding to at least two threads respectively, where the execution environments corresponding to at least two threads are independent of each other.

[0130] Step S803: Synchronize or asynchronously process at least two threads based on the execution environments respectively corresponding to the at least two threads.

[0131] The following provides a detailed description of each of the above steps:

[0132] Step S801: Obtain at least two threads to be processed.

[0133] Among them, in this embodiment, the specific obtaining method and implementation effect of the at least two threads to be processed are similar to the specific obtaining method and implementation effect of the threads to be processed in the above Step S301. For details, reference can be made to the above description, and details will not be elaborated here.

[0134] Different from the Figure 3 illustrated embodiment above, Figure 3 in the illustrated embodiment, the number of threads to be processed obtained can be one or more, while in this embodiment, the number of threads obtained is at least two.

[0135] Step S802: Determine the execution environments respectively corresponding to the at least two threads, where the execution environments respectively corresponding to the at least two threads are independent of each other.

[0136] Among them, in this embodiment, the method of determining the execution environments respectively corresponding to the at least two threads and the implementation effect are similar to the specific obtaining method and implementation effect of obtaining the execution environment in the above Step S302. For details, reference can be made to the above description, and details will not be elaborated here.

[0137] Step S803: Synchronize or asynchronously process at least two threads based on the execution environments respectively corresponding to the at least two threads.

[0138] Among them, after obtaining the execution environments respectively corresponding to the at least two threads, the at least two threads can be synchronized or asynchronously processed based on the execution environments respectively corresponding to the at least two threads. For example, the at least two threads may include Thread 1 and Thread 2. Thread 1 corresponds to Execution Environment 1, and Thread 2 corresponds to Execution Environment 2. Then, Thread 1 can be processed based on Execution Environment 1, and Thread 2 can be processed based on Execution Environment 2. Specifically, synchronization processing operations or asynchronous processing operations can be respectively performed on Thread 1 and Thread 2 based on Execution Environment 1 and Execution Environment 2, further improving the flexibility and reliability of processing the threads.

[0139] In some instances, when synchronously or asynchronously processing at least two threads based on the respective execution environments corresponding to the at least two threads, the following steps are included: obtaining data processing resources used by a thread processing device to analyze and process the at least two threads; detecting whether the data processing resources support synchronous processing of the at least two threads. Specifically, detecting whether the data processing resources support synchronous processing of the at least two threads includes: obtaining the total data resources corresponding to synchronous processing of the at least two threads, and when the data processing resources are greater than or equal to the total data resources, it is determined that the data processing resources support synchronous processing of the at least two threads, otherwise it is determined that the data processing resources do not support synchronous processing of the at least two threads.

[0140] When the data processing resources support synchronous processing of the at least two threads, the at least two threads can be synchronously processed based on the respective execution environments corresponding to the at least two threads; when the data processing resources do not support synchronous processing of the at least two threads, the at least two threads can be asynchronously processed based on the respective execution environments corresponding to the at least two threads.

[0141] In some other instances, when synchronously or asynchronously processing at least two threads based on the respective execution environments corresponding to the at least two threads, the following steps are included: obtaining the data processing efficiency of a thread processing device for asynchronously processing the at least two threads; detecting whether the data processing efficiency meets a set requirement. When the data processing efficiency is greater than or equal to the set requirement, it is determined that the data processing efficiency meets the set requirement; when the data processing efficiency is less than the set requirement, it is determined that the data processing efficiency does not meet the set requirement.

[0142] When the data processing efficiency can meet the set requirement, the thread processing device can asynchronously process the at least two threads; when the data processing efficiency cannot meet the set requirement, the thread processing device can synchronously process the at least two threads to improve the data processing efficiency.

[0143] In some other instances, when a thread processing device processes at least two threads, the processing method can change. For example, in the first period of time of processing, the thread processing device can asynchronously process the at least two threads; in the second period of time of processing, the thread processing device can synchronously process the at least two threads, which effectively improves the flexibility of processing the at least two threads.

[0144] The thread processing method provided in this embodiment obtains at least two threads to be processed, determines the execution environments corresponding to the at least two threads respectively, where the execution environments corresponding to the at least two threads are independent of each other, and synchronizes or asynchronously processes the at least two threads based on the execution environments corresponding to the at least two threads respectively. In this way, it not only effectively enables multiple processes to process corresponding tasks in their respective corresponding execution environments, effectively reduces the use of a large number of locks, reduces memory overhead, and improves the quality and efficiency of task processing. At the same time, it improves the flexibility and reliability of the use of this processing method, which is conducive to enhancing the performance of thread processing, further improving the practicality of this thread processing method, and facilitating market promotion and application.

[0145] Based on the above embodiment, continue to refer to the attached Figure 8 As shown, after synchronously or asynchronously processing the at least two threads based on the execution environments corresponding to the at least two threads respectively, the method further includes: determining a processing method for processing the at least two threads (for example: synchronous processing or asynchronous processing); and generating prompt information corresponding to the above processing method. For example, the synchronous processing method can be represented by the identifier "1", and the asynchronous processing method can be identified by the identifier "0", so that the user can know the processing method for processing the at least two threads through the displayed prompt information.

[0146] In some instances, after determining the processing method for processing the at least two threads, the thread execution efficiency (for example: thread execution time) corresponding to the above processing method can be determined, and the thread execution efficiency can be displayed, so that the user can directly and quickly obtain the thread processing efficiency corresponding to different processing methods, further improving the practicality of this method.

[0147] In specific applications, taking the Python tool as an example of the tool for establishing the execution environment, this embodiment provides a thread processing method, which includes the following steps:

[0148] Step 1: Obtain the original Python tool, which includes a built-in thread module for establishing a global exclusive lock.

[0149] Step 2: Remove the built-in thread module for establishing a global exclusive lock included in the original Python tool to obtain the Python tool.

[0150] In order to understand the specific implementation process of the thread processing method in this application embodiment, refer to the attached Figure 9As shown in the figure, the threads to be processed include Thread 1 and Thread 2. Thread 1 may include Task 1 and Task 3 to be processed, and Thread 2 may include Task 2 to be processed. The above-mentioned Task 1, Task 2, and Task 3 are independent of each other, and no Python thread can be created within the task to execute the code asynchronously. At this time, the thread execution method may include: when Thread 1 executes the corresponding Task 1, it is necessary to obtain the global exclusive lock GIL and the global interpreter, and release the GIL after Task 1 is executed; then Task 2 and Task 3 can compete for the GIL. When Task 2 obtains the GIL, it can execute Task 2 based on the GIL and the global interpreter, release the GIL after Task 2 is executed, and then Task 3 obtains the GIL and can execute Task 3 based on the GIL and the global interpreter.

[0151] In the above implementation, there is a global interpreter for providing corresponding services for executing bytecodes. The above-mentioned global interpreter is used to store Python environment-related information. The Python environment-related information may include at least one of the following: the system support type of Python, identification data, loaded modules, built-in modules, etc. When executing bytecodes, the corresponding operations of the bytecodes can be executed through the global interpreter and the GIL.

[0152] For the above implementation, if the GIL lock is removed alone, it will cause concurrency problems when multiple threads access global variables or static variables in the Python system. For example, when creating a Python object based on multiple thread tasks, when there are multiple thread tasks executing a section of code that subtracts 1 from the reference count of the above-mentioned Python object, if the parallel thread tasks are not restricted, it is very likely to cause an incorrect reference count of the Python object, which may further lead to memory leakage and even system stability problems. Therefore, after removing the GIL, it is necessary to timely restrict and protect the critical code in the thread tasks (such as: common memory areas, global variables, static variables, etc.).

[0153] Based on the above statements, in order to be able to timely restrict the critical code in the thread tasks after removing the GIL, the built-in thread module is not included in the Python tool in this embodiment. After obtaining the Python tool, an execution environment corresponding to the thread can be established using the Python tool. The data between tasks does not need to be shared in the Python environment, and effectively isolates the thread-specific data (TSD) in the thread tasks, that is, realizes the TSP isolation operation on the critical code in the thread tasks.

[0154] Specifically, in order to stably establish an execution environment corresponding to a thread, after obtaining the original Python tool, the built-in thread module for establishing a global exclusive lock included in the original Python tool is removed, so that an adjusted Python tool can be obtained. This can not only reduce the size of the data packet corresponding to the Python tool, but also facilitate the implementation of lightweight processing operations on the thread.

[0155] Step 3: Obtain the code instruction input by the user through the Python tool, and determine the thread to be processed based on the code instruction.

[0156] Among them, through the Python tool, one or more threads to be processed corresponding to the code instruction are created in the Native (Java or OC) environment.

[0157] Step 4: Use the Python tool to establish an execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other.

[0158] Among them, use the Python tool and select to create an execution environment corresponding to the thread in the Native (Java or OC) environment. Specifically, when the number of threads to be processed is multiple, the execution environments corresponding to each thread are independent of each other and do not affect each other.

[0159] Step 5: Generate an object corresponding to the task included in the thread in the execution environment, and process the object based on the task included in the thread.

[0160] Among them, since the execution environment corresponds to the thread and the execution environments corresponding to different threads are independent of each other, concurrent operations of multiple threads will not cause concurrency problems.

[0161] In some instances, after obtaining the thread to be processed, an execution environment corresponding to the thread can be created based on the thread to be processed. Or, an execution environment corresponding to the thread can be created in advance. After obtaining the thread to be processed, the thread task can be executed in the execution environment.

[0162] In some instances, after executing the thread to be processed in the execution environment, the execution environment corresponding to the thread can be destroyed; after obtaining the thread to be processed next time, an execution environment corresponding to the thread can be re-established.

[0163] For example, when the thread to be processed includes Thread 1, an execution environment corresponding to the thread can be created for Thread 1. The execution environment includes data such as an independent type system, built-in modules, and external modules corresponding to the thread. When executing a thread task, if a Python object needs to be created, the created Python object is located in the above-mentioned execution environment, and then the Python object is analyzed and processed based on the above-mentioned execution environment. When the execution is completed, the reference count of the Python object can be decremented or incremented by 1. Since the Python object is analyzed and processed in the execution environment corresponding to the thread, other threads performing parallel processing will not interfere with the Python object created by this thread.

[0164] Step 6: For the Python tool, a third-party extension library with controllable burden is configured (which is convenient for maintaining the third-party extension library), and the third-party extension library includes relevant data information for implementing extension functions.

[0165] For example, the extension function can include the function of being able to identify or parse an xml file or xml content. At this time, the third-party extension library can include the above-mentioned relevant data information for implementing the identification or parsing of an xml file or xml content.

[0166] The thread processing method provided by the embodiment of this application, by processing the Python tool to remove the built-in thread module, enables the Python tool to be unable to create a GIL, but instead can create an isolated execution environment corresponding to the thread. This greatly reduces the use of a large number of fine-grained locks caused by removing the GIL, and can implement the operation of parallel execution of Python bytecode by multiple threads, thereby greatly improving the performance target of Python. In addition, binding the thread to the corresponding execution environment, and then isolating the global and static data through the execution environment, greatly reduces the engineering cost; moreover, when applying the above thread processing method to a mobile device, an execution environment corresponding to the thread can be implemented, thereby enabling the isolation operation of multiple threads. This multi-thread isolation has a great advantage in memory compared to process isolation, further improving the practicality of the thread execution method and being conducive to market promotion and application.

[0167] Figure 10 It is a schematic structural diagram of a thread processing device provided by an embodiment of the present application; refer to the appendix Figure 10 As shown, this embodiment provides a thread processing device, and this thread processing device is used to execute Figure 3 the thread processing method shown. Specifically, this thread processing device can include:

[0168] A first acquisition module 11, configured to acquire the thread to be processed.

[0169] The first establishment module 12 is used to establish an execution environment corresponding to a thread, and the execution environments corresponding to each thread are independent of each other.

[0170] The first processing module 13 is used to process the thread in the execution environment.

[0171] In some instances, when the first establishment module 12 establishes an execution environment corresponding to a thread, the first establishment module 12 is used to execute: obtaining a Python tool for establishing the execution environment; using the Python tool to establish the execution environment.

[0172] In some instances, when the first establishment module 12 obtains a Python tool for establishing the execution environment, the first establishment module 12 is used to execute: obtaining the original Python tool; removing the built-in thread module included in the original Python tool for establishing a global exclusive lock to obtain the Python tool.

[0173] In some instances, when the first establishment module 12 uses the Python tool to establish the execution environment, the first establishment module 12 is used to execute: obtaining operation-related data corresponding to the thread; based on the operation-related data, using the Python tool to establish the execution environment.

[0174] In some instances, the operation-related data includes at least one of the following: supported language types, static data, global data, built-in modules, external modules.

[0175] In some instances, after using the Python tool to establish the execution environment, the first processing module 13 in this embodiment is used to execute: associatively storing the thread with the corresponding execution environment.

[0176] In some instances, the first processing module 13 in this embodiment is used to execute: performing thread isolation on the execution environment.

[0177] In some instances, when the first processing module 13 performs thread isolation on the execution environment, the first processing module 13 is used to execute: obtaining the global data and static data included in the execution environment; performing isolation processing on the global data and static data.

[0178] In some instances, when the first acquisition module 11 acquires the thread to be processed, the first acquisition module 11 is used to execute: obtaining code instructions; based on the code instructions, determining the thread to be processed.

[0179] In some instances, when the first processing module 13 processes a thread in an execution environment, the first processing module 13 is configured to perform: in the execution environment, generate an object corresponding to the task included in the thread; and process the object based on the task included in the thread.

[0180] In some instances, after processing the thread in the execution environment, the first processing module 13 in this embodiment is configured to perform: destroy the execution environment.

[0181] Figure 10 The device shown can execute Figures 3 - 6 the method of the embodiment shown. For parts not described in detail in this embodiment, reference may be made to the relevant descriptions of Figures 3 - 6 the embodiment shown. For the execution process and technical effects of this technical solution, refer to the descriptions in Figures 3 - 6 the embodiment shown and will not be elaborated herein.

[0182] In a possible design, Figure 10 the structure of the thread processing device shown can be implemented as an electronic device, which can be various devices such as a mobile phone, a tablet computer, a server, etc. As Figure 11 shown, the electronic device may include: a first processor 21 and a first memory 22. Among them, the first memory 22 is used to store a program for the corresponding electronic device to execute the thread processing method provided in the Figures 3 - 6 embodiment shown above, and the first processor 21 is configured to execute the program stored in the first memory 22.

[0183] The program includes one or more computer instructions. When the one or more computer instructions are executed by the first processor 21, the following steps can be implemented:

[0184] Obtain the thread to be processed;

[0185] Establish an execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other;

[0186] Process the thread in the execution environment.

[0187] Furthermore, the first processor 21 is further configured to execute all or part of the steps in the Figures 3 - 6 embodiment shown above.

[0188] Among them, the structure of the electronic device may further include a first communication interface 23, which is used for the electronic device to communicate with other devices or a communication network.

[0189] In addition, an embodiment of the present invention provides a computer storage medium for storing computer software instructions used by an electronic device, which includes instructions for executing the above Figures 3 - 6The program involved in the thread processing method in the illustrated method embodiment.

[0190] Figure 12 FIG. is a schematic structural diagram of another thread processing device provided by an embodiment of the present application; referring to the attached Figure 12 As shown, this embodiment provides another thread processing device, and this thread processing device is used to execute Figure 7 Another thread processing method shown, specifically, this thread processing device may include:

[0191] A second acquisition module 31, configured to acquire a thread to be processed and an execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other;

[0192] A second processing module 32, configured to process the thread in the execution environment.

[0193] Figure 12 The illustrated device can execute Figures 3 - 7 The method of the illustrated embodiment. For parts not described in detail in this embodiment, reference may be made to the relevant description of Figures 3 - 7 The illustrated embodiment. For the execution process and technical effects of this technical solution, refer to the description in Figures 3 - 7 The illustrated embodiment, which will not be elaborated here.

[0194] In a possible design, Figure 12 The structure of the illustrated thread processing device can be implemented as an electronic device, and this electronic device can be various devices such as a mobile phone, a tablet computer, a server, etc. As Figure 13 Shown, this electronic device may include: a second processor 41 and a second memory 42. Among them, the second memory 42 is used to store a program for the corresponding electronic device to execute the thread processing method provided in the above Figures 3 - 7 Illustrated embodiment, and the second processor 41 is configured to execute the program stored in the second memory 42.

[0195] The program includes one or more computer instructions, and when the one or more computer instructions are executed by the second processor 41, the following steps can be implemented:

[0196] Acquire a thread to be processed and an execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other;

[0197] Process the thread in the execution environment.

[0198] Further, the second processor 41 is further configured to execute all or part of the steps in the foregoing Figures 3 - 7 Illustrated embodiment.

[0199] Among them, the structure of the electronic device may further include a second communication interface 43 for the electronic device to communicate with other devices or communication networks.

[0200] In addition, an embodiment of the present invention provides a computer storage medium for storing computer software instructions used by the electronic device, which includes a program for executing the thread processing method involved in the method embodiment shown above. Figures 3 - 7 The program involved in the thread processing method in the method embodiment shown.

[0201] Figure 14 It is a schematic structural diagram of another thread processing device provided by an embodiment of the present application; referring to the attached Figure 14 As shown, this embodiment provides another thread processing device, and this thread processing device is used to execute Figure 8 Another thread processing method shown. Specifically, this thread processing device may include:

[0202] A third acquisition module 51 for acquiring at least two threads to be processed;

[0203] A third determination module 52 for determining the execution environment corresponding to each of the at least two threads, where the execution environments corresponding to each of the at least two threads are independent of each other;

[0204] A third processing module 53 for synchronously processing or asynchronously processing the at least two threads based on the execution environments corresponding to each of the at least two threads.

[0205] Figure 14 The device shown can execute Figures 3 - 6 、 Figure 8 The methods of the embodiments shown. For parts not described in detail in this embodiment, reference may be made to the relevant descriptions of the Figures 3 - 6 、 Figure 8 The execution process and technical effects of this technical solution are referred to the descriptions in the Figures 3 - 6 、 Figure 8 Embodiments shown and will not be elaborated here.

[0206] In a possible design, Figure 14 The structure of the thread processing device shown can be implemented as an electronic device, and this electronic device can be various devices such as a mobile phone, a tablet computer, a server, etc. As Figure 15 Shown, this electronic device may include: a third processor 61 and a third memory 62. Among them, the third memory 62 is used to store a program for the corresponding electronic device to execute the thread processing method provided in the Figures 3 - 6 、 Figure 8 Embodiments shown, and the third processor 61 is configured to execute the program stored in the third memory 62.

[0207] The program includes one or more computer instructions. When the one or more computer instructions are executed by the third processor 61, the following steps can be implemented:

[0208] Obtain the thread to be processed and the execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other;

[0209] Process the thread in the execution environment.

[0210] Furthermore, the third processor 61 is also used to execute all or part of the steps in the foregoing Figures 3 - 6 、 Figure 8 illustrated embodiments.

[0211] Among them, the structure of the electronic device may further include a third communication interface 63 for the electronic device to communicate with other devices or communication networks.

[0212] In addition, an embodiment of the present invention provides a computer storage medium for storing computer software instructions used by the electronic device, which includes a program involved in the thread processing method in the foregoing Figures 3 - 6 、 Figure 8 illustrated method embodiments.

[0213] Figure 16 is a schematic flowchart of a task processing method provided by an application embodiment of the present application; referring to the attached Figure 16 illustrated, the present embodiment provides a task processing method, and the execution subject of this method can be a task processing device. It can be understood that this task processing device can be implemented as software, or a combination of software and hardware. Specifically, the task processing method may include:

[0214] Step S1601: Obtain the task to be processed.

[0215] Step S1602: Generate a process corresponding to the task to be processed and at least one thread located in the process.

[0216] Step S1603: Establish an execution environment corresponding to each of the at least one thread, where the execution environments corresponding to each thread are independent of each other.

[0217] Step S1604: Synchronize or asynchronously process the at least one thread based on the execution environment corresponding to each of the at least one thread, and obtain a processing result corresponding to the task to be processed.

[0218] The following is a detailed description of each of the above steps:

[0219] Step S1601: Obtain the task to be processed.

[0220] Among them, the task to be processed refers to a task that requires data processing operations. The number of tasks to be processed can be one or more. When the number of tasks to be processed is multiple, synchronous or asynchronous processing operations can be performed on the multiple tasks to be processed. Specifically, the specific implementation manner of obtaining the task to be processed in this embodiment is similar to the specific implementation manner of obtaining the thread to be processed in the above embodiment. For specific reference, please refer to the above description and details will not be repeated here.

[0221] Step S1602: Generate a process corresponding to the task to be processed and at least one thread located in the process.

[0222] Among them, after obtaining the task to be processed, the task to be processed can be analyzed and processed to generate a process corresponding to the task to be processed and at least one thread located in the process. That is, the number of generated processes is consistent with the number of tasks to be processed, and the process can include at least one thread. The at least one thread can correspond to at least one subtask included in the task to be processed. For example, when obtaining a task to be processed that includes three subtasks, one process corresponding to the task to be processed can be generated, and the process can include three threads corresponding to the three subtasks respectively, that is, one subtask corresponds to one thread. When obtaining a task to be processed that includes five subtasks, one process corresponding to the task to be processed can be generated, and the process can include five threads corresponding to the five subtasks respectively, that is, one subtask corresponds to one thread.

[0223] Step S1603: Establish an execution environment corresponding to each of the at least one thread, where the execution environments corresponding to each thread are independent of each other.

[0224] Among them, after obtaining at least one thread, an execution environment corresponding to each of the at least one thread can be established. In addition, the specific implementation process and implementation effect of establishing the execution environment in this embodiment are similar to the specific implementation process and implementation effect of step S302 in the above embodiment. For specific reference, please refer to the above description and details will not be repeated here.

[0225] Step S1604: Perform synchronous or asynchronous processing on the at least one thread based on the execution environment corresponding to each of the at least one thread, and obtain a processing result corresponding to the task to be processed.

[0226] After obtaining at least one thread and the execution environment corresponding to each of the at least one thread, synchronous or asynchronous processing can be performed on the at least one thread based on the execution environment corresponding to each of the at least one thread, thereby effectively realizing the analysis and processing of the task to be processed, and further a processing result corresponding to the task to be processed can be obtained.

[0227] For example, when a task to be processed corresponds to a process, and the process includes Thread 1 and Thread 2, Thread 1 can correspond to Execution Environment 1, and Thread 2 can correspond to Execution Environment 2. Then, Thread 1 can be processed based on Execution Environment 1, and Thread 2 can be processed based on Execution Environment 2. Specifically, synchronization processing operations or asynchronous processing operations can be performed on Thread 1 and Thread 2 respectively based on Execution Environment 1 and Execution Environment 2, further improving the flexibility and reliability of processing the task to be processed.

[0228] The method in this embodiment may further include Figures 3 - 6 For the method of the illustrated embodiment, for parts not described in detail in this embodiment, reference may be made to the relevant description of Figures 3 - 6 the illustrated embodiment. For the execution process and technical effects of this technical solution, refer to the description in Figures 3 - 6 the illustrated embodiment and will not be elaborated here.

[0229] The task processing method provided in this embodiment obtains a task to be processed, generates a process corresponding to the task to be processed and at least one thread located in the process, then establishes an execution environment corresponding to each of the at least one thread, and synchronously or asynchronously processes the at least one thread based on the execution environment corresponding to each of the at least one thread, so as to obtain a processing result corresponding to the task to be processed. In this way, it effectively realizes that at least one process in a task to be processed can be synchronously or asynchronously processed in its corresponding execution environment, improves the quality and efficiency of task processing, and at the same time improves the flexibility and reliability of using this method, which is beneficial to improving the performance of task processing, further improving the practicability of this task processing method, and facilitating market promotion and application.

[0230] Figure 17 FIG. [ID] is a schematic structural diagram of a task processing device provided in an embodiment of the present application; refer to the attached Figure 17 As shown, this embodiment provides a task processing device, and this task processing device can execute the above Figure 16 illustrated task processing method. Specifically, this task processing device may include:

[0231] A fourth acquisition module 71, configured to acquire a task to be processed.

[0232] A fourth generation module 72, configured to generate a process corresponding to the task to be processed and at least one thread located in the process.

[0233] A fourth establishment module 73, configured to establish an execution environment corresponding to each of the at least one thread, where the execution environments corresponding to each thread are independent of each other.

[0234] The fourth processing module 74 is configured to process the at least one thread based on the execution environment corresponding to each of the at least one thread, so as to obtain a processing result corresponding to the task to be processed.

[0235] Figure 17 The device shown can execute Figure 16 the method of the embodiment shown. For parts not described in detail in this embodiment, reference may be made to the relevant descriptions of Figure 16 the embodiment shown. For the execution process and technical effects of this technical solution, refer to Figure 16 the description in the embodiment shown, which will not be elaborated here.

[0236] In a possible design, Figure 17 the structure of the task processing device shown can be implemented as an electronic device, which can be various devices such as a mobile phone, a tablet computer, a server, etc. As Figure 18 shown, the electronic device may include: a fourth processor 81 and a fourth memory 82. Among them, the fourth memory 82 is used to store a program for the corresponding electronic device to execute the task processing method provided in the above Figure 16 shown embodiment, and the fourth processor 81 is configured to execute the program stored in the fourth memory 82.

[0237] The program includes one or more computer instructions. When the one or more computer instructions are executed by the fourth processor 81, the following steps can be implemented:

[0238] Obtain a task to be processed;

[0239] Generate a process corresponding to the task to be processed and at least one thread located in the process;

[0240] Establish an execution environment corresponding to each of the at least one thread, where the execution environments corresponding to each thread are independent of each other;

[0241] Based on the execution environment corresponding to each of the at least one thread, synchronously or asynchronously process the at least one thread to obtain a processing result corresponding to the task to be processed.

[0242] Furthermore, the fourth processor 81 is further configured to execute all or part of the steps in the foregoing Figure 16 shown embodiment.

[0243] Among them, the structure of the electronic device may further include a fourth communication interface 83 for the electronic device to communicate with other devices or communication networks.

[0244] In addition, an embodiment of the present invention provides a computer storage medium for storing computer software instructions used by an electronic device, which includes instructions for executing the above Figure 16The program involved in the task processing method in the illustrated method embodiment.

[0245] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art can understand and implement it without creative effort.

[0246] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of adding a necessary general hardware platform, and of course, can also be implemented by a combination of hardware and software. Based on such an understanding, the above technical solutions, in essence, or the part that contributes to the prior art can be embodied in the form of a computer product. This application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0247] This application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of this application. It should be understood that each flow and / or block in the flowchart and / or block diagram can be implemented by computer program instructions, as well as the combination of flows and / or blocks in the flowchart and / or block diagram. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable devices generate a device for implementing the functions specified in Figure One one flow or multiple flows and / or blocks Figure One one block or multiple blocks.

[0248] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured article including an instruction device, and the instruction device implements the functions specified in Figure One one flow or multiple flows and / or blocks Figure One one block or multiple blocks.

[0249] These computer program instructions can also be loaded onto a computer or other programmable device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide for implementing the process Figure One one process or multiple processes and / or blocks Figure One steps for the functions specified in one block or multiple blocks.

[0250] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.

[0251] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM) and / or non-volatile memory such as read-only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.

[0252] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can store information by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission media that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media such as modulated data signals and carrier waves.

[0253] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, and are not intended to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements on some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A thread processing method, characterized in that, Including: Obtain the thread to be processed; Obtain the original Python tool; Remove the built-in thread module for establishing a global exclusive lock included in the original Python tool to obtain a Python tool for establishing an execution environment; Use the Python tool to establish an execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other; Process the thread in the execution environment.

2. The method according to claim 1, characterized in that, Using the Python tool to establish the execution environment includes: Obtain the operation-related data corresponding to the thread; Based on the operation-related data, use the Python tool to establish the execution environment.

3. The method according to claim 1, characterized in that After using the Python tool to establish the execution environment, the method further includes: Associatively store the thread and the corresponding execution environment.

4. The method according to claim 3, characterized in that, The method further includes: Perform thread isolation on the execution environment.

5. The method according to claim 4, wherein Performing thread isolation on the execution environment includes: Obtain the global data and static data included in the execution environment; Perform isolation processing on the global data and static data.

6. The method according to any one of claims 1-5, characterized in that Processing the thread in the execution environment includes: In the execution environment, generate an object corresponding to the task included in the thread; Based on the task included in the thread, process the object.

7. A thread processing method, characterized in that Including: Obtain the thread to be processed and the execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other, where the execution environment is established using a Python tool, and the Python tool is obtained by removing the built-in thread module for establishing a global exclusive lock included in the original Python tool; In the execution environment, process the thread.

8. A thread processing method, characterized in that, Including: Obtain at least two threads to be processed; Determine the execution environments corresponding to the at least two threads respectively, where the execution environments corresponding to the at least two threads are independent of each other, where the execution environment is established using a Python tool, and the Python tool is obtained by removing the built-in thread module for establishing a global exclusive lock included in the original Python tool; Based on the execution environments corresponding to the at least two threads respectively, perform synchronous processing or asynchronous processing on the at least two threads.

9. A task processing method, characterized in that, Including: Obtain the task to be processed; Generate a process corresponding to the task to be processed and at least one thread located in the process; Obtain the original Python tool; Remove the built-in thread module for establishing a global exclusive lock included in the original Python tool to obtain a Python tool for establishing an execution environment; Use the Python tool to establish the execution environments corresponding to the at least one thread respectively, where the execution environments corresponding to each thread are independent of each other; Based on the execution environments corresponding to the at least one thread respectively, perform synchronous or asynchronous processing on the at least one thread to obtain a processing result corresponding to the task to be processed.

10. A thread processing device, characterized in that, Including: A first acquisition module for obtaining the thread to be processed; A first establishment module for obtaining the original Python tool; Remove the built-in thread module for establishing a global exclusive lock included in the original Python tool to obtain a Python tool for establishing an execution environment; use the Python tool to establish an execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other; A first processing module for processing the thread in the execution environment.

11. An electronic device, characterized in that, Comprising: A memory and a processor; wherein, the memory is used to store one or more computer instructions, and when the one or more computer instructions are executed by the processor, the thread processing method described in any one of claims 1 to 6 is implemented.

12. A thread processing device, characterized in that, Comprising: A second acquisition module for acquiring a thread to be processed and an execution environment corresponding to the thread, and the execution environments corresponding to each thread are independent of each other, wherein the execution environment is established by using a Python tool, and the Python tool is obtained by removing the built-in thread module for establishing a global exclusive lock included in the original Python tool; A second processing module for processing the thread in the execution environment.

13. An electronic device, characterized in that, Comprising: A memory and a processor; wherein, the memory is used to store one or more computer instructions, and when the one or more computer instructions are executed by the processor, the thread processing method described in claim 7 is implemented.

14. A thread processing device, characterized in that, Comprising: A third acquisition module for acquiring at least two threads to be processed; A third determination module for determining the execution environments corresponding to the at least two threads respectively, wherein the execution environments corresponding to the at least two threads are independent of each other, and the execution environment is established by using a Python tool, and the Python tool is obtained by removing the built-in thread module for establishing a global exclusive lock included in the original Python tool; A third processing module for synchronously or asynchronously processing the at least two threads based on the execution environments corresponding to the at least two threads respectively.

15. An electronic device, characterized in that, Comprising: A memory and a processor; wherein, the memory is used to store one or more computer instructions, and when the one or more computer instructions are executed by the processor, the thread processing method described in claim 8 is implemented.

16. A task processing device, characterized in that, Comprising: A fourth acquisition module for acquiring a task to be processed; A fourth generation module for generating a process corresponding to the task to be processed and at least one thread located in the process; A fourth establishment module for acquiring the original Python tool; removing the built-in thread module for establishing a global exclusive lock included in the original Python tool to obtain a Python tool for establishing an execution environment; using the Python tool to establish the execution environments corresponding to the at least one thread respectively, wherein the execution environments corresponding to each thread are independent of each other; A fourth processing module for synchronously or asynchronously processing the at least one thread based on the execution environments corresponding to the at least one thread respectively to obtain a processing result corresponding to the task to be processed.

17. An electronic device, characterized in that, Comprising: A memory and a processor; wherein, the memory is used to store one or more computer instructions, and when the one or more computer instructions are executed by the processor, the task processing method described in claim 9 is implemented.

Citation Information

Patent Citations

  • Method for comparing packaged files and device and system thereof

    CN104199637A

  • Method and device for processing multiple runtime environment data

    CN104219078A