Asynchronous event callback method and device for scientific education
By using a single main thread and multiple coroutines asynchronously listening to event instances in the science education programming environment, the problem of not being able to effectively handle multiple concurrent events in the prior art is solved, and efficient and concise incident response and code management are achieved.
Patent Information
- Application Number
- CN202411783742.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-06
- Publication Date
- 2025-04-04
AI Technical Summary
The existing programming environment cannot effectively handle multiple concurrent events in science education, resulting in complex code, difficult to manage and maintain, and inefficient incident response.
Efficient concurrent processing of multiple events is achieved by asynchronously listening to multiple event instances using multiple coroutines in a single main thread.
It simplifies the code structure, reduces program complexity and coupling, improves event response efficiency and code readability, and supports multi-event concurrent processing.
Smart Images

Figure CN119759464A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of graphical programming, and in particular to an asynchronous event callback method and device for scientific education. Background Art
[0002] In science education, hardware programming platforms (such as micro) are widely used in programming teaching, supporting hardware control through programming languages such as Python. However, existing programming environments can usually only poll and listen to hardware events in a single thread, and cannot handle multiple events at the same time. This approach not only makes the code complex and difficult to manage, but also limits the efficiency of event response, especially when multiple concurrent events need to be handled. The existing technology lacks an effective asynchronous event processing mechanism, which makes the program logic highly coupled, increasing the difficulty of programming and maintenance costs.
[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0004] The embodiment of the present invention provides an asynchronous event callback method and device for scientific education, so as to at least solve the technical problem that a programming mainboard cannot monitor events in multiple threads.
[0005] According to one aspect of an embodiment of the present invention, an asynchronous event callback method for science education is provided, comprising: receiving multiple events defined by a graphical programming platform, and creating multiple event instances based on the multiple events; and asynchronously listening to the multiple event instances in a single main thread.
[0006] According to another aspect of an embodiment of the present invention, an asynchronous event callback device for science education is also provided, including: an event receiving module, configured to receive multiple events defined by a graphical programming platform, and create multiple event instances based on the multiple events; a listening module, configured to asynchronously listen to the multiple event instances in a single main thread.
[0007] In an embodiment of the present invention, multiple events defined by a graphical programming platform are received, and multiple event instances are created based on the multiple events; in a single main thread, the multiple event instances are asynchronously monitored through multiple coroutines. The above solution solves the technical problem that the programming mainboard cannot monitor events in multiple threads. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0009] Figure 1A flowchart of a method for asynchronous event callback for science education according to an embodiment of the present disclosure is shown;
[0010] Figure 2 A schematic diagram of the structure of an asynchronous event callback device for science education according to an embodiment of the present disclosure is shown;
[0011] Figure 3 A flowchart showing another method for asynchronous event callback for science education according to an embodiment of the present disclosure is shown;
[0012] Figure 4 A flowchart of another asynchronous event callback method for science education according to an embodiment of the present disclosure is shown;
[0013] Figure 5 A flowchart of a method for monitoring using a coroutine according to an embodiment of the present disclosure is shown;
[0014] Figure 6 A schematic diagram of the structure of another asynchronous event callback device for science education according to an embodiment of the present disclosure is shown;
[0015] Figure 7 A schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present disclosure is shown. DETAILED DESCRIPTION
[0016] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0017] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0018] According to an embodiment of the present invention, a method embodiment of an asynchronous event callback method for science education is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0019] In hardware programming teaching scenarios, Python is widely used in various programming education tools because of its simplicity and ease of learning. As a common hardware development motherboard, micro has been widely used, especially in teaching for teenagers and programming beginners. The micro motherboard has multiple input and output interfaces, including two physical buttons A and B. The status of these buttons can be read through the MicroPython programming environment for corresponding operations.
[0020] In micro's MicroPython firmware, developers can get the current pressing state (pressed or released) of button A by calling the built-in button_a.is_pressed() method. However, the existing MicroPython development environment does not provide a direct way to monitor changes in button status. For example, when a user wants to perform some operations at the moment when button A is pressed and then released, it is necessary to rely on polling to continuously check the status of the button to identify the change in the button status. Specifically, the usual implementation method is to use an infinite loop to continuously obtain the status of the button, identify the change from "pressed" to "released", and then trigger the relevant code logic. The code example is as follows:
[0021] from microbit import button_a
[0022] last_pressed_a=button_a.is_pressed()
[0023] while True:
[0024] pressed_a=button_a.is_pressed()
[0025] if(last_pressed_a and not pressed_a):
[0026] print('Button A is clicked')
[0027] last_pressed_a=pressed_a
[0028] print('will not be executed')
[0029] Although this code can realize the response of the button A click event, it has obvious shortcomings.
[0030] First, in this method, all event processing logic is concentrated in a loop body, which means that once an infinite loop is entered, the code after the loop body will not be executed. Therefore, if you need to monitor multiple events at the same time (for example, the state changes of button A and button B), you need to use multiple loop bodies to handle each event separately. This approach is not only inefficient, but also makes the organization of the code chaotic. In fact, hardware development often needs to handle multiple events, such as button pressing, releasing, temperature changes, sensor data collection, etc., which makes the processing of event monitoring more complicated.
[0031] Secondly, the existing methods rely on a single thread for event monitoring, which increases the coupling between event response codes and is not easy to intuitively organize and present the processing logic of different events. This approach is particularly unfavorable for beginners to learn, because they need to process multiple events in a large loop, which increases the complexity of the code and reduces the intuitiveness of programming.
[0032] Therefore, although the existing technology can monitor the change of button status by polling, it has obvious defects in code structure, maintainability and ease of learning, especially in the scenario of multi-event processing. In order to solve this problem, a new technical method is urgently needed to realize a more concise, intuitive and easy-to-maintain event monitoring mechanism, especially in the scenario of supporting multi-event concurrent processing.
[0033] Figure 1 is an asynchronous event callback method for science education according to an embodiment of the present invention, such as Figure 1 As shown, the method comprises the following steps:
[0034] Step S102: receiving a plurality of events defined by a graphical programming platform, and creating a plurality of event instances based on the plurality of events.
[0035] Based on a function for determining whether an event occurs, an event instance of the event is created; and the created event instance of the event is recorded in an event instance array to constitute the multiple event instances.
[0036] Specifically, the system first receives multiple events defined by the graphical programming platform, such as button presses, sensor triggers, or timer timeouts. These events will be used to trigger corresponding callback operations. According to the characteristics of each event, the system creates a function to determine whether the event has occurred, which is used to detect the triggering conditions of the event. The judgment function of each event is usually a Boolean check function. For example, the judgment function of the button press event will continuously check the button's status signal to determine whether the triggering conditions are met. Based on these judgment functions, the system generates corresponding event instances, and each event instance is associated with a specific judgment function. Next, the system records all created event instances into an event instance array. By concentrating all event instances in an array, the system can efficiently manage and allocate computing resources, providing an orderly organizational structure for subsequent asynchronous monitoring and processing.
[0037] Step S104: In a single main thread, the multiple event instances are asynchronously monitored through multiple coroutines.
[0038] An infinite loop body is created in the main thread, and computing resources are allocated to the coroutines corresponding to each of the multiple event instances one by one in the infinite loop body. For example, in the infinite loop body, an infinite loop of the corresponding coroutine is generated for each event instance; the main thread allocates the computing resources to the corresponding coroutines; thereafter, the coroutines corresponding to each event instance monitor whether the corresponding event instance occurs, and when the corresponding event is monitored to occur, the callback function of the corresponding event is executed and the computing resources are released, otherwise the computing resources are directly released.
[0039] Specifically, the system uses Python's coroutine mechanism to implement asynchronous monitoring of multiple event instances in a single main thread. Although multithreading cannot be used in the MicroPython environment of micro:bit, this embodiment can achieve the effect of asynchronous concurrency through coroutines, so that each event can be monitored and responded to independently without interfering with each other. First, an infinite loop body is created in the main thread. The loop body will traverse each event instance in the event instance array one by one and allocate computing resources for it. For each event instance, the system will create an infinite loop coroutine, which starts execution after obtaining the allocated computing resources to monitor the trigger conditions corresponding to the event instance. After each coroutine is allocated computing resources, it will check the status of its corresponding event instance. If an event is detected, the coroutine immediately calls the callback function associated with the event to respond to the event. After executing the callback, the coroutine will release the computing resources, so that the main thread can allocate resources to other coroutines for the next round of event monitoring. If the event does not occur, the coroutine directly releases the computing resources and waits for the next round of resource allocation.
[0040] In the whole process, the main thread keeps looping, allocating computing resources to the coroutine of each event instance in turn, and realizing continuous monitoring and response to all events. The asynchronous concurrent processing scheme based on coroutines in this embodiment can not only ensure the real-time monitoring of multiple events, but also decouple the code so that each event can be processed independently, reducing the complexity of the program and improving the readability of the code.
[0041] Although multithreading cannot be used in the micro:bit MicroPython environment, coroutines can be used. Using coroutines, multiple infinite loops can be iteratively executed in a single thread to achieve asynchronous concurrency. Based on python coroutines, this application proposes a technical solution for asynchronously and concurrently processing multiple event callbacks in a single thread, and realizes code decoupling between various events. This application provides an asynchronous event callback device for scientific education, such as Figure 2 As shown, it includes an event definition module 22, an event creation module 24, and an event monitoring module 26.
[0042] The event definition module 22 is used to define events. To define an event, a method is first required to determine whether the event has occurred; to respond to an event, an array of callback functions for the event is required; and to monitor events, the method is to continuously detect whether the event has occurred, and if it has occurred, the corresponding callback function is executed, so that the method of monitoring events generates an infinite loop coroutine.
[0043] The event creation module 24 is used to create an event instance. After the event class is defined, an event instance can be created based on a function that determines whether an event occurs. Each time an event instance is created, it is recorded in an array.
[0044] The event monitoring module 26 is used to monitor event instances. Using the event instance array, all event instances can be monitored at once. Each time an event instance is monitored, an infinite loop coroutine is generated, and another infinite loop is created in the main thread. In this loop body, computing resources are allocated to the coroutines of each event one by one, so that all these coroutines that were originally infinite loops will be executed.
[0045] The following describes in detail the workflow of the asynchronous event callback device for science education. Figure 3 is another asynchronous event callback method for science education according to an embodiment of the present invention, such as Figure 3 As shown, the method comprises the following steps:
[0046] Step S302, pre-package various events.
[0047] The system pre-packages a variety of events, which may include physical interaction events such as button presses and sensor triggers. By encapsulating these events, independent event instances are formed, which facilitates subsequent event management and monitoring. Each event instance encapsulates the event triggering conditions and state detection methods, allowing the system to quickly determine the triggering state of the event. The pre-packaged events are stored in an event management list, which facilitates the subsequent allocation of computing resources for monitoring one by one.
[0048] Step S304, the user references the event and registers a custom callback function;
[0049] Users can implement customized event response logic by referencing event instances. Users register corresponding callback functions for each event through the interface. The callback function will be automatically called when the event is triggered to handle the specific response operation of the event. For example, when a button is pressed, the user can register a callback function to execute a specific instruction. In this way, users can flexibly specify different processing logic for each event, which improves the scalability of the system and the control of users.
[0050] Step S306, automatically injecting code to monitor all events when burning the program;
[0051] When the user burns the program to the motherboard, the system will automatically inject code to monitor all packaged events. This automatic injection process will add an infinite loop body to the main thread of the motherboard to allocate computing resources to each event coroutine for monitoring one by one. The injected code contains the logic of event status detection and callback function execution, so that the system can automatically monitor all events after the program is burned.
[0052] Step S308, in the main board, the infinite loop operation of each monitoring event will be iteratively executed.
[0053] When waiting for computing resources, the coroutine will yield to other coroutines or the main thread, and will automatically continue to execute after obtaining computing resources. The specific execution process of each monitoring event operation is as follows Figure 3As shown. In this process, the main thread loop allocates computing resources for each event in order to listen to and respond to the occurrence of events. First listen to event A. At the beginning of the process, the main thread loop allocates computing resources for event A. After detecting the occurrence of event A, the callback function of event A is executed immediately. After executing the callback function, the computing resources are released, and the state of waiting for the allocation of computing resources is entered until the computing resources are obtained. After the coroutine that listens to event A releases the resources, the main thread starts to listen to event B. Similar to event A, the main thread loop also allocates computing resources for event B. When event B is detected, the callback function of event B is executed. Then enter the state of waiting for the allocation of computing resources until the computing resources are obtained. The main thread loop continues to allocate computing resources for other possible events. The main thread loop executes and reallocates resources for event listening to ensure that each event can be continuously listened and responded to. In this application, the entire process allocates computing resources through the main thread loop, thereby realizing asynchronous listening and processing of multiple events, so that each event can be processed without interfering with other events.
[0054] In this application, the code implementation for monitoring button A and button B being clicked can be as follows:
[0055] from helpers import click_event_a,click_event_b
[0056] def handle_click_a():
[0057] print('Button A is clicked')
[0058] def handle_click_b():
[0059] print('Button B is clicked')
[0060] click_event_a.on(handle_click_a)
[0061] click_event_b.on(handle_click_b)
[0062] #Automatic injection
[0063] #listen_all_events()
[0064] Compared with the original solution, the code of this application solution is clearer and more concise, which can intuitively present the logic of event response and reduce the learning cost for beginners.
[0065] Figure 4 is another asynchronous event callback method for science education according to an embodiment of the present invention, such as Figure 4 As shown, the method comprises the following steps:
[0066] Step S402, define event class.
[0067] First, define the event class to encapsulate various types of events. In Python, you can create an event class Event, which is used to abstractly represent all types of events. The event class contains the following key elements: Event status check method: used to determine whether an event has occurred. Each event has a specific trigger condition. For example, a button click event can be determined by detecting changes in the button state. Callback function list: Each event can be bound to multiple callback functions. When an event is triggered, these callback functions will be executed in sequence. Event type identification: used to distinguish different types of events. For example, identifiers or labels can be used to distinguish between button A click events, button B click events, etc., so that different event types can be managed and called later.
[0068] Secondly, implement the event status check method. When defining an event class, you need to implement a check method, such as is_triggered(), to determine whether the event is triggered. This method is implemented according to the specific type of event and the triggering condition. Taking the button click event as an example, the logic of the status check method is: detect the change of the button state (i.e. from pressed to released) to determine whether the event occurs. This method will be called every time the main thread loop allocates resources to determine whether the event triggering condition is met.
[0069] Then, set up the callback function management mechanism. One of the core of event encapsulation is to manage the registration and calling of callback functions. Each event object contains a list of callback functions. When the event is triggered, all callback functions in the list will be executed in sequence. In order to implement this mechanism, an add_callback() method can be defined in the event class, through which users can bind custom callback functions to the event. After the event is triggered, the event object will call the execute_callbacks() method to execute the registered callback functions in sequence. In this way, event response is more flexible, and users can add, delete or replace callback functions as needed.
[0070] Step S404: create an event instance.
[0071] After defining the event class, create specific event instances according to the needs of the teaching scenario. For example, create a click event for button A and a click event for button B. When creating an event instance, you need to specify the trigger condition detection method and identifier for each event. These instantiated events will be stored in an event management list for subsequent unified management and monitoring in the main thread. For example, you can use an array or list to save all event objects. In this way, in the subsequent event monitoring step, you can loop through the list to detect the status of each event one by one, thereby achieving unified management of multiple events.
[0072] Step S406, using a coroutine to monitor.
[0073] In order to achieve efficient monitoring of multiple events, the present invention provides a monitoring mechanism based on coroutines. The mechanism creates an infinite loop in the main thread and allocates computing resources to the coroutines corresponding to each event instance one by one, ensuring that each event can be continuously monitored and quickly responded to.
[0074] Specific implementation is as follows Figure 5 As shown, the following steps are included:
[0075] Step S4062: the main thread creates an infinite loop body.
[0076] Initialize an infinite loop in the main thread to continuously allocate computing resources to the monitoring coroutine of each event. This loop will continue to execute during the program running to ensure real-time monitoring of all events.
[0077] Step S4064, mapping of event instances and coroutines.
[0078] As mentioned above, each event instance has been encapsulated and stored in a management list. The main thread will traverse the event management list one by one and map each event instance to a separate coroutine. Each coroutine is used to monitor the triggering status of the corresponding event and execute the callback function when it is triggered.
[0079] Step S4066, allocating computing resources one by one.
[0080] In the infinite loop, the main thread allocates computing resources to the monitoring coroutine of each event in turn. This process is similar to the time slice round-robin scheduling mechanism, that is, in each loop, computing resources are only provided to the coroutine of a single event so that it can check the trigger status of the event. In this way, the fairness of multiple event monitoring is ensured, and it is avoided that a certain event occupies too many resources and affects the monitoring of other events.
[0081] Step S4068, the coroutine monitors the event status.
[0082] After the coroutine obtains computing resources, it calls the is_triggered() method of the event instance to check whether the event is triggered. If it detects that the event has not occurred, the coroutine will immediately release the computing resources and let the main thread continue to allocate resources for the next event. If the event is detected to have occurred, the coroutine will do the following: call the callback function of the event and perform the event response operation. After executing the callback function, the coroutine will immediately release the computing resources to ensure that other coroutines can obtain resources in time and continue to listen to other events.
[0083] When the coroutine detects the occurrence of an event and executes the callback function, the computing resources will be released. In this way, the event monitoring and response operations will not occupy computing resources for a long time, thereby improving the system's response speed and resource utilization efficiency. After the callback function is executed, the coroutine will enter a waiting state until the next main thread loop allocates resources again.
[0084] The infinite loop of the main thread will be executed continuously, allocating resources for the event coroutine to achieve continuous monitoring of multiple events. Through the asynchronous characteristics of the coroutine, even in a single-threaded environment, it is still possible to efficiently monitor and respond to multiple events, making the system have a concurrency effect similar to multi-threading.
[0085] This embodiment has the following beneficial effects: 1) Efficient resource utilization: The main thread allocates resources one by one to ensure that each event coroutine has the opportunity to check the event status. The coroutine releases resources immediately when no event is detected, avoiding invalid occupation of resources. 2) Improved response speed: When an event occurs, the coroutine immediately responds and executes the callback function to achieve fast event processing, thereby improving the event response speed. 3) Support for asynchronous event monitoring: Through the asynchronous mechanism of the coroutine, concurrent monitoring and response of multiple events are achieved in a single-threaded environment, avoiding the blocking problem of traditional infinite loops.
[0086] The present application also provides an asynchronous event callback device for science education, such as Figure 6 As shown, it includes: an event receiving module 62, which is configured to receive multiple events defined by the graphical programming platform and create multiple event instances based on the multiple events; a monitoring module 64, which is configured to asynchronously monitor the multiple event instances in a single main thread.
[0087] It should be noted that the asynchronous event callback device for scientific education provided in the above embodiment is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the asynchronous event callback device for scientific education provided in the above embodiment and the asynchronous event callback method embodiment for scientific education belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0088] The present application also provides a graphical education system for science education, including: a graphical programming platform for defining multiple events; a teaching programming mainboard connected to the graphical programming platform for executing the above-mentioned asynchronous event callback method for science education.
[0089] A graphical programming platform is a programming environment for beginners, educational users, and non-professional developers. It simplifies the traditional code writing process through a visual operation interface, allowing users to create programs by dragging and connecting modules without having to master complex syntax. The platform usually contains a series of visual code blocks or graphical modules, each of which represents a programming function or operation, such as "control", "event", "variable", "loop", "logic", etc. Users can splice these modules together to form a logical flow and achieve programming goals.
[0090] In the graphical programming platform, the programming operation is highly abstract. Different functions are encapsulated into graphic blocks of different colors, and users can connect these function blocks by simply dragging and dropping. For example, users can connect the "When a button is pressed" event module with the "Perform an action" module to achieve the effect of triggering a specific operation when the button is pressed. This method greatly reduces the threshold for learning programming and is particularly suitable for children, programming beginners and non-technical personnel, helping them to understand programming logic and computer thinking more intuitively.
[0091] In addition, graphical programming platforms usually support converting visual code blocks into actual programming code. The platform will generate corresponding programming language codes such as Python or JavaScript from these graphical blocks in the background. In this way, users can gradually transition from graphical programming to text programming and gain a deeper understanding of programming.
[0092] Educational programming boards, such as Micro, are small development boards designed for educational purposes. Their small size makes it easy for beginners and students to learn programming, electronics, and IoT-related knowledge. The board has a variety of built-in functional modules to provide a rich programming and hardware interaction experience at the entry level. Micro, as one of the most widely used educational programming boards, is equipped with a variety of sensors, displays, and interfaces, allowing students to approach hardware programming in an intuitive way.
[0093] The Micro mainboard integrates multiple hardware modules. For example, it contains an LED dot matrix display for displaying text, numbers or patterns, making information transmission more intuitive. There are two programmable buttons (A and B) on the mainboard, which can be used to detect user presses and trigger specific events. In addition, Micro is also equipped with an accelerometer and a magnetometer. The former is used to detect the movement or tilt of the board, and the latter can act as an electronic compass to detect the current direction. Through the Bluetooth and USB interfaces, Micro can communicate with other devices to realize data transmission. The GPIO pins on the mainboard support the connection of external devices or sensors, providing users with an interface to expand hardware functions.
[0094] Micro can interact seamlessly with the graphical programming platform, thus reducing the difficulty of learning programming. Through the graphical programming platform, users can drag and drop code blocks to build logic without having to write complex code directly. For beginners, the graphical interface provided by the platform makes hardware control and programming more intuitive, lowering the learning threshold. After programming is completed, students can burn the code to the Micro motherboard via USB or Bluetooth, and the motherboard will then execute the programming commands. In this way, students can see the programming effect in real time, making programming learning more vivid and visual, and promoting hands-on practice and the cultivation of logical thinking. Before burning, the graphical programming platform can also perform a logical check on the code. For example, the first eigenvector of the context code of the code to be detected and the second eigenvector of the current code to be detected are extracted respectively, and the first eigenvector and the second eigenvector are respectively upgraded according to the extended rank criterion, and the first eigenvector and the second eigenvector are coupled and fused using a multi-channel convolution kernel to obtain the coupled main embedding feature matrix and auxiliary embedding feature matrix. The above matrix is expanded along the direction of the extended dimension to form multiple sub-matrices. Each sub-matrix is subjected to singular value decomposition to extract the core subspace representation and factor matrix. The principal component differences between the main feature matrix and the auxiliary feature matrix are calculated based on the core subspace representation and the factor matrix to extract the core features, thereby effectively identifying logical errors and reference problems.
[0095] Figure 7 FIG. 1 shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiment of the present disclosure. It should be noted that: Figure 7The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0096] like Figure 7 As shown, the electronic device includes a central processing unit (CPU) 1001, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage part 1008 into a random access memory (RAM) 1003. In the RAM 1003, various programs and data required for system operation are also stored. The CPU 1001, the ROM 1002, and the RAM 1003 are connected to each other via a bus 1004. An input / output (I / O) interface 1005 is also connected to the bus 1004.
[0097] The following components are connected to the I / O interface 1005: an input section 1006 including a keyboard, a mouse, etc.; an output section 1007 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1008 including a hard disk, etc.; and a communication section 1009 including a network interface card such as a LAN card, a modem, etc. The communication section 1009 performs communication processing via a network such as the Internet. A drive 1010 is also connected to the I / O interface 1005 as needed. A removable medium 1011, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1010 as needed, so that a computer program read therefrom is installed into the storage section 1008 as needed.
[0098] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. An asynchronous event callback method for science education, characterized in that: include: Receiving a plurality of events defined by a graphical programming platform, and creating a plurality of event instances based on the plurality of events; In a single main thread, the multiple event instances are asynchronously monitored through multiple coroutines.
2. The method according to claim 1, characterized in that: In a single main thread, multiple event instances are asynchronously monitored through multiple coroutines, including: Creating an infinite loop in the main thread, and allocating computing resources to the coroutines corresponding to each event instance in the multiple event instances one by one in the infinite loop; The coroutine corresponding to each event instance monitors whether the corresponding event instance occurs, and when the corresponding event occurs, executes the callback function of the corresponding event and releases the computing resources, otherwise directly releases the computing resources.
3. The method according to claim 2, characterized in that Allocating computing resources to the coroutines corresponding to each of the multiple event instances one by one in the infinite loop body includes: In the infinite loop body, for each event instance, an infinite loop corresponding coroutine is generated; The main thread allocates the computing resources to the corresponding coroutine.
4. The method according to claim 2, characterized in that: Creating a plurality of event instances based on the plurality of events includes: Based on a function for determining whether an event occurs, creating an event instance of the event; The event instance of the created event is recorded in the event instance array to constitute the multiple event instances.
5. The method according to any one of claims 1 to 4, characterized in that The method is applied on a teaching programming mainboard connected to the graphical programming platform.
6. An asynchronous event callback device for scientific education, characterized in that: include: An event receiving module, configured to receive a plurality of events defined by the graphical programming platform, and create a plurality of event instances based on the plurality of events; The monitoring module is configured to asynchronously monitor the multiple event instances in a single main thread.
7. A graphical education system for science education, characterized in that: include: Graphical programming platform for defining multiple events; A teaching programming mainboard, connected to the graphical programming platform, is used to execute the method described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the method according to any one of claims 1 to 5.
9. A computer device, characterized in that: include: Memory and processor, The memory stores a computer program; The processor is used to execute the computer program stored in the memory, and when the computer program is run, the processor is enabled to execute the method according to any one of claims 1 to 5.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.