Skip to content

Attempt to adapt asynchronous I/O#121

Open
qeggs-dev wants to merge 8 commits into
alessandromaggio:devfrom
qeggs-dev:dev
Open

Attempt to adapt asynchronous I/O#121
qeggs-dev wants to merge 8 commits into
alessandromaggio:devfrom
qeggs-dev:dev

Conversation

@qeggs-dev

Copy link
Copy Markdown

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

qeggs-dev added 8 commits June 8, 2026 21:50
- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant