create multiple separate memory filesystems · Issue #1904 · fsspec/filesystem_spec · GitHub
Skip to content

create multiple separate memory filesystems #1904

Closed

Description

@milahu

fsspec/implementations/memory.py

class MemoryFileSystem(AbstractFileSystem):
    """A filesystem based on a dict of BytesIO objects

    This is a global filesystem so instances of this class all point to the same
    in memory filesystem.
    """

    store: ClassVar[dict[str, Any]] = {}  # global, do not overwrite!
    pseudo_dirs = [""]  # global, do not overwrite!

... ok, but i need multiple different memory filesystems in parallel

assert (
    fsspec.filesystem("memory://").store !=
    fsspec.filesystem("memory://").store
)

this should be as simple as moving store and pseudo_dirs to def __init__

maybe add a new protocol localmemory

Activity

  1. martindurant commented on Aug 7, 2025

    @martindurant
    Member

    This is a reasonable idea and something I thought of doing in the past. The reason it hasn't happened yet, is that MemoryFS is used extensively in tests - in fact, that is the main use case - and it if often useful not to have to carry variable handles around.

    Note that:

    assert (
        fsspec.filesystem("memory").store !=
        fsspec.filesystem("memory").store
    )
    

    would only be true if the filesystem is not cachable, otherwise you get the identical python object: fsspec.filesystem("memory") is fsspec.filesystem("memory").

    fsspec.get_filesystem_class("memory").cachable is True
    
  2. martindurant commented on Aug 7, 2025

    @martindurant
    Member

    In short: if you can make the change and no tests fail (or can be easily fixed), let's do it. Note that the documentation will need to be updated.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions