gitrepo_top_sample_50 / substrate_interface /docs /usage /cleanup-and-context-manager.md
Dorothydu's picture
Upload 50 random repository samples
9d3c8f5 verified

Cleanup and context manager

At the end of the lifecycle of a SubstrateInterface instance, calling the close() method will do all the necessary cleanup, like closing the websocket connection.

When using the context manager this will be done automatically:

with SubstrateInterface(url="wss://rpc.polkadot.io") as substrate:
    events = substrate.query("System", "Events")

# connection is now closed