Fix event loop issue and support multi-client#45
Open
WordlessMeteor wants to merge 4 commits intosousa-andre:masterfrom
Open
Fix event loop issue and support multi-client#45WordlessMeteor wants to merge 4 commits intosousa-andre:masterfrom
WordlessMeteor wants to merge 4 commits intosousa-andre:masterfrom
Conversation
Adapted BaseConnector's event loop to Python 3.14.0 asyncio library.
1. Adapted `utils._return_ux_process` function, so that a list of processes, instead of only one process, are returned. Discussion: By a generator returned, the memory used is supposed to be significantly reduced, but in this case, since a user normally won't run multiple League Clients on one device, the memory cost difference between returning a generator and returning a list of processes shouldn't be too much. 2. Discuss about the number of running League Clients (namely the number of LeagueClientx.exe) through `connector.chooseClient` function. (1) If no client is found, raise a new error `NoLeagueClientDetected`; (2) if one client is found, build connection with that process; (3) otherwise, display the process list and let the user decide which client process to build connection with. While I was rewriting `utils._return_ux_process` function, two optimizations were made. 1. Optimized the running time of `_return_ux_process` funtion. (1) Avoiding a zombie process by always checking a process' `status` method significantly increases the time expense. Therefore, A try-except statement is used to handle exceptions triggered by accessing the attribute of a zombie process. (2) (Windows only) Accessing the cmdline attribute of a process significantly increases the time expense. Since LeagueClientUx.exe always has the correct name on Windows, there's no need to access a process' cmdline attribute on Windows. 2. Adjusted some type annotations. Note that these type annotations rely on Python ≥ 3.9.
Optimized the prompt layout when multiple clients are detected. By "+2", each pair of neighboring cells should be delimited by at least 2 spaces.
Now, when there's more than one League Client running and the library outputs multiple options to connect to, users may enter nothing, namely directly press Enter, to select the process with the latest creation time. To select another process, users still need to enter the process index shown in "No." column. Besides, adjusted some code based on the strict type checking mode: One variable should have only one type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
asyncio.eventsis changed: an event loop must be explicitly created before callingget_event_loop. The modified version has been proved running normally with Python 3.14 installed._return_ux_processfunction, especially on Windows. Before this optimization, even if only one League Client is running, it still took about 5 seconds to connect to that client. After this optimization, with multiple League Clients running, it only takes about 1 second to show the entire process list. In the case where no League Client is running, the old Generator approach would cause the program stuck in the event loop, searching for any League Client that might be launched, but without given explicit prompt. Now, if no League Client is found, this library should give an explicit message and interrupt the program execution. Note that this condition can be reinforced to identifying the running League Client processes instead of only found processes, if this commit can be approved. You may check more details in the commit description.Note: