{
  "$type": "site.standard.document",
  "canonicalUrl": "https://rednafi.com/python/use-daemon-threads-to-test-infinite-loop/",
  "description": "Test Python infinite loops safely using daemon threads with timeouts, allowing tests to complete without hanging or blocking execution.",
  "path": "/python/use-daemon-threads-to-test-infinite-loop/",
  "publishedAt": "2021-11-18T00:00:00.000Z",
  "site": "at://did:plc:fgtm2c26vfcj74rfmeggbyqj/site.standard.publication/3mnl6f7ob462z",
  "tags": [
    "Python",
    "Testing",
    "Concurrency"
  ],
  "textContent": "Python's daemon threads are cool. A Python script will stop when the main thread is done and\nonly daemon threads are running. To test a simple hello function that runs indefinitely,\nyou can do the following:\n\nTo execute the script, make sure you've your virtual env actiavated. Also you'll need to\ninstall pytest and pytest-asyncio. Then run:\n\nThe idea came from this [Quora answer].\n\n\n\n\n[quora answer]:\n    https://qr.ae/pGDHVw",
  "title": "Use daemon threads to test infinite while loops in Python"
}