Registry / web-framework / mode
library4.4.0pypypi✓ verified 84d ago

Mode is an async service-based programming library built on top of asyncio. It provides Service, Worker, and BackgroundThreadService classes for composing asynchronous services. Current version is 4.4.0, requires Python ~=3.6. Release cadence is irregular.

pip install mode
INSTALL
IMPORT
SIG · MODE
M
mode
web-frameworkpythonv4.4.0
Install
1.7s avg
Import
299ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.318s · 18.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.280s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Service
from mode import Service
Correct import path for the base Service class.
Worker
from mode import Worker
Correct import for Worker loop.
BackgroundThreadService
from mode import BackgroundThreadService
Used for services running in separate threads.

Simple example of creating and running a Mode Service.

import asyncio from mode import Service class MyService(Service): async def run(self) -> None: while not self.should_stop: await asyncio.sleep(1) print('Service running') async def main(): service = MyService() await service.start() await asyncio.sleep(5) await service.stop() if __name__ == '__main__': asyncio.run(main())
Debug
Known issues
deprecatedThe 'Worker' class is deprecated in favor of 'Service' for custom services. Use Service as base for new code.
fix
Replace 'class MyWorker(Worker)' with 'class MyService(Service)' and adjust run() accordingly.
affects: >=4.0.0
breakingIn version 4.0.0, the 'run()' method signature changed: it no longer takes an 'async' generator approach but must be a coroutine. Old code using 'yield' in run() breaks.
fix
Change run() to be an async def that uses await asyncio.sleep() or other async patterns instead of yield.
affects: >=4.0.0
gotchaService.start() must be awaited; common mistake is to call start() without await, leading to unstarted services.
fix
Always use 'await service.start()' inside an async context.
affects: all
gotchaAvoid overriding '__init__' in subclasses unless you call super().__init__() properly. Missing super() can break internal state.
fix
If you override __init__, always call 'super().__init__(**kwargs)' at the end of your __init__.
affects: all
Errors
Common errors & fixes
RuntimeError: Task <Task pending ...> got Future <Future pending ...> attached to a different loop
Mixing services created in different event loops, often due to threading or incorrect loop handling.
fix
Ensure all Mode services are created and started within the same event loop. Use 'asyncio.get_event_loop()' consistently or 'asyncio.run()' for top-level.
TypeError: 'async_generator' object is not iterable
Using yield in Service.run() which is a coroutine, not an async generator.
fix
Change run() to use async/await pattern: 'async def run(self): await asyncio.sleep(...)' instead of 'while True: yield await ...'.
Upgrade
Version history
4.4.0latest on PyPI · released Sep 28, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
20
OpenAI (training)
1
Resources
mode — pip install mode · libregistry