A Python-based task polling method and task management system
Through the task polling method based on PYTHON, the hierarchical relationship between the main thread-task pool sub-task sub-thread is established, which solves the management problems of timed tasks and periodic tasks in software projects, and realizes centralized management and stable and efficient task execution across projects.
Patent Information
- Application Number
- CN202210544355.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-19
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2042-05-19
AI Technical Summary
The existing technology has cumbersome configuration of timing tasks and cycle tasks in software project development, which is not easy to manage and monitor, and cannot achieve centralized control across projects. Especially when using the PYTHON and Java mechanisms, there are problems such as task loss, difficulty in positioning, and difficulty in changing.
The task polling method based on PYTHON is adopted to start the task pool subthread through the main thread. The task pool subthread traverses all tasks of the task pool according to the startup time, acquires and starts the task subthread, establishes the hierarchical relationship between the main thread-task pool subthread-task subthread, and realizes centralized control of timed tasks and periodic tasks of multiple projects.
It realizes timed tasks and cycle tasks for each project across projects, improves the stability and efficiency of the system, avoids task loss, reduces system overhead, and supports dynamic modification of execution time.
Smart Images

Figure CN114936077B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software development, and in particular to a Python-based task polling method, a task management system, a computer device, and a storage medium. Background Art
[0002] With the rapid development of software development technology, the complexity and scale of software systems are increasing day by day. However, in software project development, there are problems such as cumbersome configuration of scheduled tasks and periodic tasks, and difficulty in management and monitoring, which has become an urgent problem to be solved.
[0003] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute prior art known to ordinary technicians in the field. Summary of the Invention
[0004] In order to solve at least one of the above problems, a first embodiment of the present invention provides a task polling method based on Python, comprising:
[0005] Start the main thread;
[0006] Start a task pool subthread, so that the task pool subthread traverses all tasks in the task pool according to the first start time at which it is started, obtains a task whose task execution time matches the first start time, and starts the task subthread of the task;
[0007] Wait for a preset first time interval and jump to the step of starting the task pool subthread.
[0008] Furthermore, the step of starting the task pool subthread further includes:
[0009] Start the task pool thread so that:
[0010] The task pool subthread obtains the first startup time and outputs the first startup format time according to a preset time format;
[0011] querying the task in the task pool according to the first startup format time, and if the startup time of the queried task is the same as the first startup format time, starting the task sub-thread of the task, so that the task sub-thread executes the task;
[0012] Determine whether the current task is the last task in the task pool. If not, jump to the step of querying the task pool according to the first startup format time. If so, end the task pool sub-thread.
[0013] Furthermore, before the step of starting the task pool sub-thread, the tasks in the task pool are traversed at a preset second time interval to filter out invalid tasks.
[0014] Furthermore, before the step of starting the task pool sub-thread, the start time of each task in the task pool is converted into a start format time that conforms to the time format and stored;
[0015] The step of querying the task pool according to the first startup format time further includes: querying the task pool according to the first startup format time, and if the startup format time of the queried task is the same as the first startup format time, starting the task sub-thread of the task, so that the task sub-thread executes the task.
[0016] Furthermore, the step of waiting for a preset first time interval and jumping to the starting task pool subthread further includes:
[0017] Initialize the time compensation value, obtain the start time of the task pool sub-thread, compare it with the preset time reference and record the time difference;
[0018] Determining whether the time difference exceeds a preset time threshold, and if so, storing the time difference in the time compensation value;
[0019] Wait for the sum of the first time interval and the time compensation value, and jump to the step of starting the task pool sub-thread.
[0020] Furthermore, the step of starting the main thread further includes:
[0021] Start the main thread and set the main thread identifier;
[0022] Get the global identifier and determine the main thread identifier based on the global identifier. If the two are consistent, jump to the step of starting the task pool sub-thread. If the two are inconsistent, end the main thread.
[0023] A second embodiment of the present invention provides a Python-based task management system, comprising a task management device, at least one project, each project comprising at least one task, wherein the task management device is configured to:
[0024] Start the main thread;
[0025] Starting a task pool sub-thread, wherein the task pool sub-thread traverses all tasks in the task pool according to the first start time at which it is started, obtains a task whose task execution time matches the first start time and starts the task sub-thread of the task, wherein the task pool includes tasks of each project;
[0026] Wait for a preset first time interval and jump to the step of starting the task pool subthread.
[0027] A third embodiment of the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the method described in the first embodiment is implemented.
[0028] A fourth embodiment of the present invention provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first embodiment when executing the program.
[0029] The beneficial effects of the present invention are as follows:
[0030] In response to the current existing problems, the present invention develops a Python-based task polling method, a task management system, a computer device, and a storage medium. The method starts a task pool sub-thread through a main thread, and the task pool sub-thread traverses all tasks in the task pool according to the start time, and starts the sub-thread of the task that meets the start time to execute the task, thereby establishing a hierarchical relationship of main thread-task pool sub-thread-task sub-thread, and completing the centralized control of the scheduled tasks of multiple projects through this hierarchical relationship, realizing cross-project management of scheduled tasks and periodic tasks of various projects, and having practical application significance. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0032] Figure 1 A task polling flow chart according to an embodiment of the present invention is shown;
[0033] Figure 2 A structural diagram showing a task management system according to an embodiment of the present invention;
[0034] Figure 3 A flowchart of a task management device according to an embodiment of the present invention is shown;
[0035] Figure 4 A flowchart of starting a main thread according to an embodiment of the present invention is shown;
[0036] Figure 5 A flowchart of starting a task pool subthread according to an embodiment of the present invention is shown;
[0037] Figure 6A flowchart showing the polling judgment according to an embodiment of the present invention is shown;
[0038] Figure 7 A schematic structural diagram of a computer device according to another embodiment of the present invention is shown. DETAILED DESCRIPTION
[0039] In order to more clearly illustrate the present invention, the present invention is further described below in conjunction with preferred embodiments and accompanying drawings. Similar components in the accompanying drawings are represented by the same reference numerals. It should be understood by those skilled in the art that the following detailed description is illustrative rather than restrictive and should not be used to limit the scope of protection of the present invention.
[0040] In the prior art, there are two main ways to trigger scheduled tasks or periodic tasks: the first is to use the Python-based Django and Celery mechanism, which requires importing the corresponding software library in each business system and performing relatively complex configuration. Once a problem occurs, it is difficult to troubleshoot, locate, and change it. In particular, in actual applications, tasks may be lost, and centralized management and control across projects cannot be achieved; the second is to use a Java-based timer. Although this method will not lose tasks, it is limited by the operating mechanism of the Java language itself and cannot dynamically modify the execution time. When the execution time needs to be modified, the entire service must be restarted, and this method also cannot achieve centralized management and control across projects.
[0041] In response to the problems existing in the existing technology, the inventor proposed a lightweight application solution after extensive research and experiments to solve the timing tasks and periodic task triggering processing involved in software projects, and to achieve centralized management and control across projects.
[0042] like Figure 1 As shown, an embodiment of the present invention provides a task polling method based on Python, comprising:
[0043] Start the main thread;
[0044] Start a task pool subthread, wherein the task pool subthread traverses all tasks in the task pool according to the first start time at which it is started, obtains a task whose task execution time matches the first start time, and starts the task subthread of the task;
[0045] Wait for a preset first time interval and jump to the step of starting the task pool subthread.
[0046] This embodiment starts the task pool sub-thread through the main thread, and the task pool sub-thread traverses all tasks in the task pool according to the start time, and starts the sub-thread of the task that meets the start time to execute the task, thereby establishing a hierarchical relationship of main thread-task pool sub-thread-task sub-thread, and completing the centralized control of scheduled tasks of multiple projects through this hierarchical relationship, realizing cross-project management of scheduled tasks and periodic tasks of various projects, which has practical application significance.
[0047] In a specific embodiment, Figure 2 As shown, the present invention also provides a Python-based task management system, including a task management device, at least one project, each project including at least one task. The task management system of this embodiment is for multiple tasks in multiple projects, and the task management device is used to manage and schedule task operations for each project. The task management system of this embodiment can be a local server, a remote server, or a cloud server.
[0048] The following is an explanation of the task polling in an actual operation process, such as Figure 1 and Figure 3 As shown, the specific process of the task management device operation is as follows:
[0049] Step 1, S20: Start the main thread,
[0050] In this embodiment, the main thread is started first. The main thread is the main program of the server and realizes the management and scheduling of various tasks of various projects.
[0051] Considering the problem of starting multiple main threads due to misoperation in actual applications, in an optional embodiment, Figure 4 As shown, further comprising:
[0052] S202: Start the main thread and set the main thread identifier.
[0053] S204: Obtain a global identifier and determine the main thread identifier based on the global identifier. If the global identifier and the main thread identifier are consistent, jump to S40; if the global identifier and the main thread identifier are inconsistent, terminate the main thread.
[0054] In this embodiment, to prevent multiple main threads from being started due to accidental operation, a global identifier and a main thread identifier are set. The main thread identifier is used to uniquely identify the currently running instance, and may include, but is not limited to, a string of characters to distinguish each main thread instance. The global identifier is used to determine whether the current main thread is already running. Specifically, after the main thread is started, the global identifier is read. If the global identifier is empty, the main thread identifier is set to the global identifier, and the current main thread is now the only running main thread. If the global identifier is not empty and is inconsistent with the main thread identifier, it indicates that the current main thread was started by mistake, and the main thread is exited, thus terminating the mistakenly started main thread.
[0055] It is worth noting that the present invention does not make any specific limitation on the generation algorithm of the main thread identifier. Those skilled in the art can implement it according to a conventional algorithm. In this embodiment, it is generated by combining a timestamp, a device network card MAC address, and a random number.
[0056] This embodiment uses the set global identifier and the main thread identifier for comparison, which effectively avoids the error of repeated running of the main thread. In actual engineering practice, it provides fault-tolerant protection for the erroneous start of the main thread, effectively improving the stability and robustness of the system.
[0057] The second step is Figure 1 As shown, S40: start the task pool sub-thread, so that the task pool sub-thread traverses all tasks in the task pool according to its first start time, obtains the task whose task execution time matches the first start time and starts the task sub-thread of the task.
[0058] In this embodiment, the task pool sub-thread is started by the main thread, and the task pool sub-thread is used to poll each task of each project, thereby reducing the system overhead of the main thread for each task and improving the operating efficiency and stability of the main thread.
[0059] In an optional embodiment, if Figure 5 As shown, further comprising:
[0060] S402: Start the task pool thread.
[0061] In this embodiment, first, the main thread starts the task pool sub-thread.
[0062] S404: The task pool sub-thread obtains the first startup time and outputs a first startup format time according to a preset time format.
[0063] In this embodiment, the task pool sub-thread obtains the start time of the task pool sub-thread, i.e., the first start time, and converts the first start time into a first start format time in a preset time format. In this embodiment, the preset time format is a minute-based time format, for example, the start time of the current task pool sub-thread is the minute of the current natural day.
[0064] It is worth noting that the minute-based time format of this embodiment is only used to illustrate the specific implementation of this embodiment. This application does not specifically limit the time format. Those skilled in the art should select an appropriate time format based on actual application requirements, using the start time of the current task pool sub-thread as the design criterion. This will not be repeated here. S406: Query the task pool according to the first startup format time. If the start time of the queried task is the same as the first startup format time, start the task sub-thread of the task, so that the task sub-thread executes the task.
[0065] In this embodiment, the first startup format time of the current task pool sub-thread is used as the screening basis, and each task in the task pool is queried and judged to determine whether the startup time of each task is the same as the first startup format time, for example, whether it falls within the first startup format time. If the startup time is the same as the first startup format time, the task sub-thread is asynchronously started to execute the task.
[0066] Taking into account the operating efficiency and compatibility of the task management system, in an optional embodiment, the task polling method further includes:
[0067] The start time of each task in the task pool is converted into a start format time that conforms to the time format and stored.
[0068] In this embodiment, by presetting the start time format of each task, the start time of each task is unified with the format of the first start format time obtained by the task pool sub-thread.
[0069] The S406 further includes: querying the task in the task pool according to the first startup format time, and if the startup format time of the queried task is the same as the first startup format time, starting the task sub-thread of the task, so that the task sub-thread executes the task.
[0070] In this embodiment, by comparing two times in the same format, the speed of time comparison is effectively improved, thereby reducing the time overhead of the task pool thread.
[0071] In a specific example, the task pool contains three tasks, of which the start time of task 1 is 10:35:15, the start time of task 2 is 17:08:43, and the start time of task 3 is 21:55:38. Considering that the first start time is in minute format, the start time of each task is also converted to minute format.
[0072] Specifically, since the first start time is in a minute-based format, seconds are omitted when converting the task's start time to a minute-based format. For example, the start time of the first task is converted to 635 minutes, which is the number of minutes counted from the early morning of that day. All tasks from 0 seconds to 59 seconds of that minute fall within this minute. Similarly, the start time of the second task is converted to 1028 minutes, and the start time of the third task is converted to 1315 minutes.
[0073] The task judgment method based on formatted time described in this embodiment can simplify complex timestamp comparison into minute comparison with consistent format, thereby improving operation efficiency. In particular, when the task system runs 7X24 uninterruptedly, this method can also improve the stability and compatibility of the system.
[0074] It should be noted that this application does not specifically limit the time format. Those skilled in the art should select an appropriate time format based on actual application requirements, which will not be elaborated here.
[0075] S408: Determine whether the current task is the last task in the task pool. If not, jump to S406. If yes, end the task pool sub-thread.
[0076] In this embodiment, the tasks in the task pool are traversed by determining whether the current task is the last task in the task pool. Specifically, if it is not the last task, the next task is queried and determined. If it is the last task, the current task pool sub-thread is ended to realize polling of all tasks in the task pool.
[0077] In actual application, after the task pool subthread is started by the main thread, it uses the first startup format time to traverse each task in the task pool, compares the startup format time of each task with the first startup format time of the current task pool subthread, and starts the task subthread to execute the task if they are equal. If the current task is the last task in the thread pool, the task pool subthread is terminated. In other words, the life cycle of the task pool subthread is to respond to the startup of the main thread, traverse each task in the task pool using the first startup format time, and start the task subthread for the task with the same startup time as the first startup format time.
[0078] Taking into account the operating efficiency of the task management system, in an optional embodiment, the task polling method further includes: before S40, traversing the tasks in the task pool at a preset second time interval to filter out invalid tasks.
[0079] In this embodiment, considering that some tasks in the task pool may become invalid tasks, the tasks in the task pool are filtered according to a preset time interval, thereby further improving the polling efficiency of the task pool sub-thread on each task.
[0080] Specifically, considering that under normal circumstances, the time it takes for the main thread to call the task pool child thread each time should theoretically be less than 10 milliseconds, but considering that the scale of the task management system is particularly large and the number of tasks managed is large, it is particularly necessary to streamline the task pool in a timely manner, especially considering that the task management system runs 24 / 7, and task filtering can effectively improve the work efficiency of task polling.
[0081] It is worth noting that the present application does not make any specific limitation on the invalid tasks, which can be defined by technical personnel in this field according to specific project requirements, for example, tasks that have expired or tasks that have failed to be called multiple times are filtered out; at the same time, the present application does not make any specific limitation on the filtering time of invalid tasks, which can be performed according to the second time interval period or according to application requirements; technical personnel in this field should select appropriate task filtering strategies according to actual application requirements, with improving the operating efficiency of task polling as the design criterion, which will not be elaborated here.
[0082] Step 3, S60: Wait for a preset first time interval and jump to S40.
[0083] In this embodiment, the task pool sub-threads are repeatedly started according to a preset first time interval, thereby reducing the system overhead of the main thread for each task and improving the operation efficiency and operation stability of the main thread.
[0084] To further improve the stability of the main thread, in an optional embodiment, as Figure 6 As shown, further comprising:
[0085] S602: Initialize the time compensation value, obtain the start time of the task pool sub-thread, compare it with the preset time reference and record the time difference;
[0086] S604: Determine whether the time difference exceeds a preset time threshold, and if so, store the time difference in the time compensation value;
[0087] S606: Wait for the sum of the first time interval and the time compensation value, and jump to S40.
[0088] In the present embodiment, when described main thread is opened described task pool subthread at each turn, although adopt asynchronous call, but each operation all can need certain time overhead, should be lower than 10 milliseconds under normal circumstances, but consider that the task management system designed by the present invention needs 7X24 hour uninterrupted operation, therefore after long-time accumulation, must produce time deviation.For guaranteeing the accuracy of task system, present embodiment presets a time threshold, for example, is 500 milliseconds, utilize this time threshold that the start time of task pool subthread is judged, when the start time of the task pool subthread of main thread and the time difference of time benchmark are greater than this time threshold, use time difference to compensate.
[0089] In a specific example, the first time interval is 60 seconds, the time base is 00 seconds 000 milliseconds per minute, the time threshold is 500 milliseconds, and the time compensation value is initialized to 0. During operation:
[0090] The start time of the task pool thread started by the main thread for the first time is 0 minutes, 00 seconds, 000 milliseconds. The main thread waits for an interval of 60 seconds before starting the task pool thread.
[0091] The start time of the second task pool thread started by the main thread is 1 minute 00 seconds 10 milliseconds. The time difference is 10 milliseconds, which is less than the time threshold of 500 milliseconds. The main thread still waits at an interval of 60 seconds and then starts the task pool thread.
[0092] The main thread continues to run;
[0093] The start time of the task pool thread started by the main thread for the nth time is n minutes 00 seconds 505 milliseconds, so the time difference is 505 milliseconds, which is greater than the time threshold of 500 milliseconds, and the time difference is stored in the time compensation value; at this time, the time compensation value and the time interval are used to determine the waiting time of the main thread, that is, the time difference is used to compensate the time interval, so the waiting time of the main thread this time is 60 seconds + time difference - 505 milliseconds, and the waiting time is 59 seconds 495 milliseconds, and then the task pool thread is started;
[0094] The start time of the task pool thread started by the main thread for the n+1th time is n+1 minutes 00 seconds 000 milliseconds. The time compensation value is initialized to 0. The main thread waits for a time interval of 60 seconds before starting the task pool thread.
[0095] This embodiment uses the above-mentioned time threshold judgment and time difference compensation method to avoid time deviations accumulated due to long-term continuous operation, or time deviations caused by program operation jams due to individual special circumstances. It can ensure the accurate execution of tasks, avoid task loss, and further ensure that tasks are executed stably and accurately.
[0096] At this point, the task polling of the task management system is completed.
[0097] This embodiment has the following advantages:
[0098] First, by establishing a hierarchical relationship of main thread-task pool sub-thread-task sub-thread, and through this hierarchical relationship, centralized control of scheduled tasks of multiple projects is completed, realizing cross-project management of scheduled tasks and periodic tasks of various projects.
[0099] Secondly, the system operation efficiency is improved. Each comparison only requires comparing two integers, without the need for complex conversion and comparison.
[0100] Thirdly, the tolerance of the system is improved. Because the system runs uninterruptedly for a long time, although a threshold protection mechanism has been added, there will still be slight time deviations within the threshold. This method can accommodate slight time deviations by setting the time threshold, ensuring stable operation of the system.
[0101] Finally, the flexibility of the system is improved. By setting the time format, the task polling time is further reduced and the task polling method is optimized.
[0102] Taking into account the compatibility of the task management system, in an optional embodiment, the task polling method further includes:
[0103] Configuring a task interface for at least one task in the task pool to execute the task;
[0104] The S406 further includes: querying the task in the task pool according to the first startup format time, and if the startup time of the queried task is the same as the first startup format time, starting the task sub-thread of the task, so that the task sub-thread executes the task by calling the task interface.
[0105] This embodiment configures a task interface in the task and further implements the execution of the task through the configured task interface. That is, the task management system implements the execution of the task by calling the task interface. Those skilled in the art should understand that the task interface can also be used to record task execution results, exception notifications, etc., thereby effectively lightweighting the task management system on the basis of centralized management of multiple tasks of multiple projects.
[0106] In this embodiment, the task interface includes but is not limited to the following interface forms: for example, an interface using the HTTP protocol in an Internet environment, an interface using the MQTT protocol in an Internet of Things environment, an interface using the SMS protocol in a networkless environment, and an interface using the Bluetooth or NFC protocol in a near-field environment.
[0107] In a specific example, for example, in an Internet-based office system, the personnel system needs to compile a list of personnel who were late or left early the previous day at 8:00 am every morning. Using the task management system described in the present invention, the developer of the personnel system only needs to provide an HTTP protocol interface, such as using a network address URL as a task interface, and configure the task management system to call this interface at 8:00 am every day. There is no need to develop logic for scheduled task execution. This allows personnel system developers to focus on the personnel system-related logic without having to master or worry about the development of logic related to scheduled tasks. Other protocol forms are not described in detail.
[0108] In this embodiment, developers in this field can uniformly configure the task management system described in the present invention according to specific application requirements and environments, targeting different systems and different usage environments, thereby achieving centralized control of scheduled tasks for multiple projects.
[0109] Based on the above PYTHON-based task polling method, such as Figure 2 As shown, an embodiment of the present invention further provides a task management system based on Python, comprising a task management device, at least one project, each project comprising at least one task, wherein the task management device is configured to:
[0110] Start the main thread;
[0111] Starting a task pool sub-thread, wherein the task pool sub-thread traverses all tasks in the task pool according to the first start time at which it is started, obtains a task whose task execution time matches the first start time and starts the task sub-thread of the task, wherein the task pool includes tasks of each project;
[0112] Wait for a preset first time interval and jump to the step of starting the task pool subthread.
[0113] This embodiment addresses the existing problems. By starting a task pool subthread through the main thread, the task pool subthread traverses all tasks in the task pool according to the start time, and starts the subthread of the task that meets the start time to execute the task, thereby establishing a hierarchical relationship of main thread-task pool subthread-task subthread, and completing the centralized control of the scheduled tasks of multiple projects through this hierarchical relationship, realizing cross-project management of scheduled tasks and periodic tasks of various projects. The specific implementation of this embodiment is shown in the previous embodiment and will not be repeated here.
[0114] Another embodiment of the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the program implements: a Python-based task management system, comprising a task management device, at least one project, each project including at least one task, wherein the task management device is configured to:
[0115] Start the main thread;
[0116] Starting a task pool subthread, causing the task pool subthread to traverse all tasks in the task pool according to a first start time at which it is started, obtaining a task whose task execution time matches the first start time and starting the task subthread of the task, wherein the task pool includes tasks of each project;
[0117] Wait for a preset first time interval and jump to the step of starting the task pool subthread.
[0118] In practical applications, the computer-readable storage medium can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or component, or any combination thereof. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present embodiment, the computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0119] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0120] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0121] Computer program code for performing the operations of the present invention may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0122] like Figure 7 As shown, a structural diagram of a computer device provided by another embodiment of the present invention. Figure 7 The computer device 12 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0123] like Figure 7 As shown, computer device 12 is implemented as a general-purpose computing device. Components of computer device 12 may include, but are not limited to, one or more processors or processing units 16, system memory 28, and a bus 18 that connects various system components (including system memory 28 and processing unit 16).
[0124] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. Examples of these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0125] The computer device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer device 12, including volatile and non-volatile media, removable and non-removable media.
[0126] System memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. Computer device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be configured to read and write non-removable, non-volatile magnetic media ( Figure 7 Not shown, often called a "hard drive"). Although Figure 7 Not shown, a magnetic disk drive for reading and writing to a removable non-volatile magnetic disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 via one or more data media interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of various embodiments of the present invention.
[0127] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may include an implementation of a network environment. Program modules 42 generally implement the functions and / or methods of the embodiments described herein.
[0128] The computer device 12 may also communicate with one or more external devices 14 (e.g., a keyboard, a pointing device, a display 24, etc.), one or more devices that enable a user to interact with the computer device 12, and / or any device that enables the computer device 12 to communicate with one or more other computing devices (e.g., a network card, a modem, etc.). Such communication may occur through an input / output (I / O) interface 22. Furthermore, the computer device 12 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 20. Figure 7 As shown, the network adapter 20 communicates with the other modules of the computer device 12 via the bus 18. Figure 7 Not shown, other hardware and / or software modules may be used in conjunction with computer device 12, including but not limited to microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0129] The processor unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, such as the task polling method described in the present invention.
[0130] In response to the current existing problems, the present invention develops a Python-based task polling method, a task management system, a computer device, and a storage medium. The method starts a task pool sub-thread through a main thread, and the task pool sub-thread traverses all tasks in the task pool according to the start time, and starts the sub-thread of the task that meets the start time to execute the task, thereby establishing a hierarchical relationship of main thread-task pool sub-thread-task sub-thread, and completing the centralized control of the scheduled tasks of multiple projects through this hierarchical relationship, realizing cross-project management of scheduled tasks and periodic tasks of various projects, and having practical application significance.
[0131] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the present invention, and are not limitations on the implementation methods of the present invention. For ordinary technicians in the relevant field, other different forms of changes or modifications can be made based on the above description. It is impossible to list all the implementation methods here. All obvious changes or modifications derived from the technical solution of the present invention are still within the scope of protection of the present invention.
Claims
1. A task polling method based on Python, characterized in that: include: Start the main thread; Start a task pool sub-thread; wherein, the task pool sub-thread traverses all tasks in the task pool according to the first start time at which it is started, obtains a task whose task execution time matches the first start time and starts the task sub-thread of the task; Waiting for a preset first time interval and jumping to the step of starting the task pool subthread; The step of waiting for a preset first time interval and jumping to the starting task pool subthread further includes: Initialize the time compensation value, obtain the start time of the task pool sub-thread, compare it with the preset time reference and record the time difference; Determining whether the time difference exceeds a preset time threshold, and if so, storing the time difference in the time compensation value; Wait for the sum of the first time interval and the time compensation value, and jump to the step of starting the task pool sub-thread.
2. The task polling method according to claim 1, characterized in that: The step of starting the task pool thread further includes: Start the task pool thread so that: The task pool subthread obtains the first startup time and outputs the first startup format time according to a preset time format; querying the task in the task pool according to the first startup format time, and if the startup time of the queried task is the same as the first startup format time, starting the task sub-thread of the task, so that the task sub-thread executes the task; Determine whether the current task is the last task in the task pool. If not, jump to the step of querying the task pool according to the first startup format time. If so, end the task pool sub-thread.
3. The task polling method according to claim 2, characterized in that: Before the step of starting the task pool sub-thread, the task polling method further includes: The tasks in the task pool are traversed at a preset second time interval to filter out invalid tasks.
4. The task polling method according to claim 3, characterized in that: Before the step of starting the task pool sub-thread, the task polling method further includes: converting the start time of each task in the task pool into a start format time that conforms to the time format and storing the time format; The step of querying the task pool according to the first startup format time further includes: querying the task pool according to the first startup format time, and if the startup format time of the queried task is the same as the first startup format time, starting the task sub-thread of the task, so that the task sub-thread executes the task.
5. The task polling method according to claim 2, characterized in that: Before the step of starting the task pool sub-thread, the task polling method further comprises: configuring a task interface for at least one task in the task pool to execute the task; The step of querying the tasks in the task pool according to the first startup format time further includes: querying the tasks in the task pool according to the first startup format time, and if the startup time of the queried task is the same as the first startup format time, starting the task sub-thread of the task, so that the task sub-thread executes the task by calling the task interface.
6. The task polling method according to any one of claims 1 to 5, characterized in that: The step of starting the main thread further includes: Start the main thread and set the main thread identifier; Get the global identifier and determine the main thread identifier based on the global identifier. If the two are consistent, jump to the step of starting the task pool sub-thread. If the two are inconsistent, end the main thread.
7. A task management system based on Python, characterized in that: The system comprises a task management device, at least one project, each project comprising at least one task, wherein the task management device is configured to: Start the main thread; Starting a task pool sub-thread, wherein the task pool sub-thread traverses all tasks in the task pool according to the first start time at which it is started, obtains a task whose task execution time matches the first start time and starts the task sub-thread of the task, wherein the task pool includes tasks of each project; Wait for a preset first time interval and jump to the step of starting the task pool thread; The step of waiting for a preset first time interval and jumping to the starting task pool subthread further includes: Initialize the time compensation value, obtain the start time of the task pool sub-thread, compare it with the preset time reference and record the time difference; Determining whether the time difference exceeds a preset time threshold, and if so, storing the time difference in the time compensation value; Wait for the sum of the first time interval and the time compensation value, and jump to the step of starting the task pool sub-thread.
8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Multi-thread concurrency monitoring method, device and apparatus and storage medium
CN111488255A