
Product
Introducing Reports: An Extensible Reporting Framework for Socket Data
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.
monitored-ioloop
Advanced tools
A production ready monitored IO loop for Python.
No more wondering why your event loop (or random pieces of your code) are suddenly popping up as slow in your monitoring.
pip install monitored_ioloop # For the default event loop
pip install monitored_ioloop[uvloop] # For the the additional support of the uvloop event loop
📺 Play with the demo in sandbox
The loop factory approach is the recommended way to use monitored event loops. This approach is preferred by Python's asyncio documentation as it provides more flexibility and allows running asyncio without the policy system.
from monitored_ioloop.monitored_asyncio import monitored_asyncio_loop_factory
from monitored_ioloop.monitoring import IoLoopMonitorState
import asyncio
import time
def monitor_callback(ioloop_state: IoLoopMonitorState) -> None:
print(ioloop_state)
async def test_coroutine() -> None:
time.sleep(2)
def main():
loop_factory = monitored_asyncio_loop_factory(monitor_callback)
asyncio.run(test_coroutine(), loop_factory=loop_factory)
if __name__ == "__main__":
main()
In order to use the uvloop event loop, please make sure to install monitored_ioloop[uvloop].
from monitored_ioloop.monitored_uvloop import monitored_uvloop_loop_factory
from monitored_ioloop.monitoring import IoLoopMonitorState
import asyncio
import time
def monitor_callback(ioloop_state: IoLoopMonitorState) -> None:
print(ioloop_state)
async def test_coroutine() -> None:
time.sleep(2)
def main():
loop_factory = monitored_uvloop_loop_factory(monitor_callback)
asyncio.run(test_coroutine(), loop_factory=loop_factory)
if __name__ == "__main__":
main()
For backward compatibility, you can still use the event loop policy interface:
from monitored_ioloop.monitored_asyncio import MonitoredAsyncIOEventLoopPolicy
from monitored_ioloop.monitoring import IoLoopMonitorState
import asyncio
import time
def monitor_callback(ioloop_state: IoLoopMonitorState) -> None:
print(ioloop_state)
async def test_coroutine() -> None:
time.sleep(2)
def main():
asyncio.set_event_loop_policy(MonitoredAsyncIOEventLoopPolicy(monitor_callback))
asyncio.run(test_coroutine())
The monitor callback will be called for every execution that the event loop initiates.
With every call you will receive an IoLoopMonitorState object that contains the following information:
callback_wall_time: Wall executing time of the callback.loop_handles_count: The amount of handles (think about them as tasks) that the IO loop is currently handling.loop_lag: The amount of time it took from the moment the task was added to the loop until it was executed.callback_pretty_name: The pretty name of the callback that was executedAs many of you might be concerned about the performance impact of this library, I have run some benchmarks to measure the performance impact of this library.
In summary the performance impact is negligible for most use cases.
You can find the more detailed information in the following README.md.
You can find examples projects showing potential use cases in the examples folder.
Currently there is only the fastapi with prometheus exporter example but more will be added in the future.
Handle's on the event loopHandle are making the event loop sloweruvicornFAQs
Unknown package
We found that monitored-ioloop demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Explore exportable charts for vulnerabilities, dependencies, and usage with Reports, Socket’s new extensible reporting framework.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.