Skip to content

Provide a way to drop resources in Python Land #18

@erikrose

Description

@erikrose

In some instances, it is necessary to promptly drop resources: for example, to grab a second request for Fastly's session-reuse feature. Currently, we use an ugly hack:

# Here we abuse an arbitrary request-consuming function to trigger
# the drop. Glue code interposed by wasmtime's linker ensures that
# drop happens, but send() otherwise fails before doing anything.
send(request, body, "no such backend")

Without this, a trap occurs at await_request(), IIRC. (If I don't recall correctly, it's at next_request().)

I see 2 ways out of this:

  1. Convince the Python runtime to drop things that Python itself GCs (either because refcount drops to 0 or because the cyclic GC ditches them). This would enable us to implement explicit drops in our SDK by simply saying del some_resource behind nice abstractions. Customers could also call del if they wanted to program at a lower level. Most of the time, I imagine we could do nothing and let scope exits take care of dropping things.
  2. If that proves difficult for some reason, we could generate a drop_foo() (likely in componentize-py) for each resource type foo and call those instead of del.

Open question:

  • How are drops currently effected? Are they at all?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions