Attempt to adapt asynchronous I/O#121
Open
qeggs-dev wants to merge 8 commits into
Open
Conversation
- Add close() method for explicit socket cleanup - Implement __enter__ and __exit__ for with-statement support - Update __del__ to call close() instead of direct socket.close() - Enables proper resource management using 'with Socket(...) as s'
- Add _create_socket static method for socket instantiation - Allow subclasses to override socket creation (e.g., async socket) - Add close() method to properly close the underlying socket - Implement __enter__ and __exit__ for with-statement support
- Create new aionetwork.py module for async socket support - Add AsyncSocket inheriting from Socket with non-blocking socket - Implement async send() using loop.sock_sendto - Implement async receive() using asyncio.wait_for and loop.sock_recvfrom - Set socket to non-blocking mode for asyncio integration
- Create new aioexecutor.py module for async executor support - Add AsyncCommunicator inheriting from Communicator - Override _create_socket to return AsyncSocket instead of Socket - Implement async send_ping() for sending ICMP requests - Implement async listen_for() for receiving and matching responses - Implement async run() to perform all pings asynchronously - Use asyncio.sleep() instead of time.sleep() for non-blocking intervals
… ping - Create new aioping.py module for async ping API - Add aping() function with same parameters as sync ping() - Use AsyncCommunicator with context manager for proper resource cleanup - Maintain same payload provider logic (Repeat/Sweep) as sync version - Support DF flag via AsyncSocket.DONT_FRAGMENT - Reuse SEED_IDs mechanism for thread-safe unique identifiers - Update docstring: 'Async ping to remote host handling responses'
- Import aping from .aioping module - Make async ping available via pythonping.aping()
- Move SEED_IDs.remove(seed_id) inside with block - Move return comm.responses inside with block - Ensures proper ordering of resource cleanup and response return - Prevents potential issues when socket cleanup is needed before return
- Replace explicit Communicator instantiation with with-statement - Move SEED_IDs.remove(seed_id) inside with block - Move return comm.responses inside with block - Ensures socket is properly closed even if run() throws exception - Maintains identical behavior and return value
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.
Attempts to use an asynchronous network request
This may result in the minimum Python version required for the project being raised to 3.7
尝试使用异步的网络请求
这可能会导致项目所需的最低 Python 版本提升到 3.7