Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions examples/python/transfer_queue_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ async def main():
logger.info("=== Transfer Queue Example ===\n")

try:
# Initialize pulsing (user must call this explicitly)
await pul.init()

# Get an async client for partition "demo"
client = pul.transfer_queue.get_async_client(
partition_id="demo", num_buckets=2, batch_size=4
Expand Down Expand Up @@ -90,9 +87,8 @@ async def main():
logger.info("Example completed!")

finally:
await pul.shutdown()
logger.info("System shutdown")
logger.info("Example finished (transfer_queue runtime cleanup is automatic)")


if __name__ == "__main__":
asyncio.run(main())
asyncio.run(main())
17 changes: 3 additions & 14 deletions examples/python/transfer_queue_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
python examples/python/transfer_queue_sync.py
"""

import asyncio
import logging
import threading

import pulsing as pul

Expand All @@ -23,16 +21,10 @@
def main():
logger.info("=== Transfer Queue Sync Client Example ===\n")

# 1) Create a background event loop and initialize pulsing on it
loop = asyncio.new_event_loop()
threading.Thread(target=loop.run_forever, daemon=True, name="pulsing-loop").start()
asyncio.run_coroutine_threadsafe(pul.init(), loop).result(timeout=30)
logger.info("Pulsing initialized\n")

try:
# 2) Get a sync client (using the background loop)
# 1) Get a sync client. transfer_queue bootstraps Pulsing internally.
client = pul.transfer_queue.get_client(
partition_id="demo_sync", num_buckets=2, batch_size=4, loop=loop
partition_id="demo_sync", num_buckets=2, batch_size=4
)
logger.info("Transfer queue client created (2 buckets, batch_size=4)\n")

Expand Down Expand Up @@ -88,10 +80,7 @@ def main():
logger.info("Example completed!")

finally:
# 3) Shutdown pulsing and stop the background loop
asyncio.run_coroutine_threadsafe(pul.shutdown(), loop).result(timeout=10)
loop.call_soon_threadsafe(loop.stop)
logger.info("System shutdown")
logger.info("Example finished (transfer_queue runtime cleanup is automatic)")


if __name__ == "__main__":
Expand Down
Loading
Loading