socket_asyncio_threaded
socket_asyncio_threaded, or sockco as I like to call it, is a python library to send and receive data with asyncio.StreamReader, asyncio.StreamWriter in another single thread.
Simple Usage
import socket_asyncio_threaded.client as sockco
if __name__ == '__main__':
client = sockco.SocketClient()
# Choose a ReceiveHandler from sockco like RH_Splitter, RH_HeaderSize,
# or implement your own handler
client.start_async(MOCK_SERVER_ADDR, MOCK_SERVER_PORT, sockco.RH_Splitter())
# Now do something you want and write data at any time
client.write_async(bytes(f'ping\n', encoding='utf-8'))
# When needed, just read a pack of data, no need to be concerned about when to receive
msg = client.read_async()
Background and Notes
This code is used in my project which needs to read and write data with socket occasionally. If only asyncio is used, the event loop needs to run in the main thread; and reading/writing data from different threads needs a little bit more resource than coroutine. So I decided to put them together, which is this library.
Some notes I'd like to mention:
-
Only client-side is available, and the implementation of server-side is under schedule.
-
The lifecycle of SocketClient is the same as StreamReader, so it is not allowed to write data after the receiving direction is closed, even if the sending direction is still open.
About
Version: 0.0.2
Auther: S3Studio
Url: https://github.com/S3Studio/socket_asyncio_threaded
New issues are welcomed
Metadata
Release files for socket-asyncio-threaded 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| socket_asyncio_threaded-0.0.2.tar.gz | 4.4 kB | Without provenance | Details for socket_asyncio_threaded-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| socket_asyncio_threaded-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for socket_asyncio_threaded-0.0.2-py3-none-any.whl |
Total release size: 9.3 kB
Release files / socket_asyncio_threaded-0.0.2.tar.gz
| Download URL | socket_asyncio_threaded-0.0.2.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
62408e0e973f8a393026c9fdd89c191163a96dac20f14eb80703d63c0b1e9d74
|
|
BLAKE2b-256 checksum How to use checksums |
8421bb3d1090aca8cd231735824427ef08768e75eca60de95d8a64e02b7afb9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8
|
Release files / socket_asyncio_threaded-0.0.2-py3-none-any.whl
| Download URL | socket_asyncio_threaded-0.0.2-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d499e7a1911df63cd86beed760cac54a0ef27d16c50fbd3ab9aaa82279bb538
|
|
BLAKE2b-256 checksum How to use checksums |
43db666406cee4bd914a226ba8cfc6bffc1773b283f9948778f8dda2ed7ed20a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8
|
Security for socket-asyncio-threaded 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.