Skip to content

asyncio #438

Open
Open

Description

@aspizu

provide asyncio functions in addition to blocking ones

Activity

  1. TheCommCraft commented on Jun 18, 2025

    @TheCommCraft
    Collaborator
  2. aspizu commented on Jun 18, 2025

    @aspizu
    Author

    use httpx it has an async client

  3. faretek1 commented on Jun 23, 2025

    @faretek1
    Collaborator

    should/would this be done as a separate submodule, a seperate repository,or a seperate branch? or something else?

  4. faretek1 commented on Jun 23, 2025

    @faretek1
    Collaborator

    and then upload to pypi as sa-async or something?

  5. TheCommCraft commented on Jun 23, 2025

    @TheCommCraft
    Collaborator

    I'd say a submodule just for async event handlers and also async versions of site classes in the same files as the blocking ones

  6. TheCommCraft commented on Jun 23, 2025

    @TheCommCraft
    Collaborator

    If anything, I would have be an extra like pip install scratchattach[async]

  7. TheCommCraft commented on Jun 24, 2025

    @TheCommCraft
    Collaborator

    I could create a milestone for this and you could create a pull request if you wanr

  8. faretek1 commented on Jul 1, 2025

    @faretek1
    Collaborator

    aiohttp is faster than httpx, but is more cumbersome to use, and i dont think the difference is that significant.
    if we are zo use httpx, it would be worth considering stopping using requests for the sync side of things.

    Also, since async with httpx would require an AsyncClient to be used anyway, it might be worth partially restructuring the library to use requests.Session/httpx.Client objects instead of storing headers and cookies seperately. There could be a Session/Client object as an attribute of ever session object, e.g. with the name rq. so it'd become self.rq.get(url),or self._sess.rq.get(url). the only problem is data validation.

  9. faretek1 commented on Jul 1, 2025

    @faretek1
    Collaborator

    n.b. scapi uses aiohttp

  10. TheCommCraft commented on Jul 1, 2025

    @TheCommCraft
    Collaborator

    maybe we could create an internal api for creating api calls like with uplink but for async and sync simultaneously

  11. added
    enhancement
    on Aug 1, 2025
  12. added this to the async milestone on Dec 20, 2025
  13. moved this from Todo to asyncio in scratchattachon Dec 20, 2025
  14. faretek1 commented on Dec 20, 2025

    @faretek1
    Collaborator
  15. moved this from asyncio to Todo in scratchattachon Dec 21, 2025
  16. self-assigned this
    on Jan 31, 2026
  17. faretek1 commented on May 4, 2026

    @faretek1
    Collaborator

    greenlet is hard

    synchronicity is less mainstream and requires .aio. it adds these dynamically though so you need typing stubs. even so, it doesnt really give you a great API surface. msoft's playwright-python uses greenlet and has a pretty nice api so i was suggesting we go with that. however it appears that playwright also has some kind of codegen process? It still has a much nicer API surface than synchronicity though and greenlet seems more well-supported. idk

    tcc mentioned using uplink. this seems fascinating. how viable is this?

  18. removed their assignment
    on May 4, 2026
  19. pinned this issue on May 4, 2026
  20. linked a pull request that will close this issueasyncio #599on May 7, 2026
  21. faretek1 commented on Jul 27, 2026

    @faretek1
    Collaborator

    I am coming to the opinion again that manually maintaining both synchronous and asynchronous code may be the best choice.

    • It does not require unorthodox tooling
      • so it is easier to learn the codebase as a newbie
      • so it is easier to maintain even after we leave
      • so we dont have to maintain internal tools
    • It does not use magic - we would not have any magic constants or functions or a preprocessor
      • this makes it easier to understand the codebase (if there is magic, it is much harder to learn)
      • new contributors/maintainers can come and go without as much danger to the project
      • it is vanilla python code, so anyone can understand it by reading it. they do not need to know about our specific strange build process and internal code generation tool

    however as with all choices here, there are downsides, the main one here being the need to write everything twice

    • so individual features take longer to be made
    • or extra abstractions have to be added

    however this can be somewhat mitigated by having a separate component for the internal logic of handling the data itself (e.g. return User(data["username"], id=data["user-id"], some_other_field=data["foobar"])), but making synchronous and asynchronous wrappers around them.

    • this means that there is a need to understand how the codebase is structured
      • however this is already part of the contributor documentation so we can just amend that
      • we would then try our best to keep the sync, async, and core toplevel submodules tightly organized, having, if possible the exact same directory hierarchy/structure.
    • this will make implementing 1 feature meaning having to add core code, as well as sync/async wrappers, and also tests for the async/sync wrappers. However, in fact, if we make unit tests on the core submodule, we could easily create the "mock tests" that i described in improve test suite #703 without even having to monkeypatch anything.
    • This would mean that we would need a good upgrade to our contributor documentation.

    The reason i emphasize easiness to understand is because in my opinion, scratchattach should serve as a good transition point to go from a basic python user to an actually decent python user. For a project with the target demographic of scratch users aiming to do something cool with scratch (only using python as a means to that end), i think this is the right approach

    In terms of async, i think either we should: a. do it manually (it hurts but at the same time so does everything) OR b. redirect users to scapi by kakeruzoku

    another option is to put async on extremely low priority, redirect users to scapi, refactor the codebase so it is satisfactory in the other regards, and then, and only then, do the core/async refactor. Since this is an open source project, we are not constrained by deadlines, so this approach is possible. However, progress is not guaranteed (this is essentially the path we are taking right now)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions