Futures
Easy Async
Futures are a powerful tool in Dandy that allow you to run code asynchronously which is great for non-blocking calls like network requests.
All you need to do on any class that has a process
method is to call the process_to_future
method instead.
Without Async Futures
Let's run three LlmBot.process
calls at once and see how long it takes.
from time import perf_counter
from dandy import Bot
start_time = perf_counter()
pants_intel = Bot().process('What type of pants should I wear in the rain?')
shirt_intel = Bot().process('What type of shirt should I wear in the sun?')
shoes_intel = Bot().process('What type of shoes should I wear in the mud?')
print('Pants: ' + pants_intel.content)
print('Shirt: ' + shirt_intel.content)
print('Shoes: ' + shoes_intel.content)
print(f'Finished in {perf_counter() - start_time:.3f} seconds')
Pants: For rainy weather, you should wear pants made from waterproof or water-resistant materials. Here are some good options:
1. **Rain pants or waterproof pants** - These are specifically designed for wet conditions and often have waterproof membranes or coatings
2. **Waterproof jeans** - Some denim is treated with waterproof coatings or is made from water-repellent fabrics
3. **Synthetic materials** - Pants made from polyester, nylon, or other synthetic fabrics that repel water
4. **Waterproof hiking pants** - These are durable and often have features like reinforced knees and adjustable cuffs
5. **Cotton pants treated with waterproofing** - Some cotton pants are treated with waterproof coatings
Avoid regular cotton pants as they absorb water and become heavy and uncomfortable. Look for pants with waterproof zippers, seams, and possibly a waterproof rating (like 10,000mm or higher). If you're going to be standing in rain for extended periods, consider wearing waterproof pants over regular pants for extra protection.
Shirt: For sun protection, you should wear a long-sleeved shirt made from tightly woven, UV-resistant fabric. Look for shirts with UPF (Ultraviolet Protection Factor) rating of 50 or higher, which blocks over 98% of UV rays. Light-colored fabrics like white, light blue, or pastels are ideal as they reflect sunlight rather than absorb it. Avoid thin, loosely woven materials like cotton t-shirts, which offer little protection. If you're swimming or sweating, choose moisture-wicking fabrics that maintain their UV protection even when wet. A wide-brimmed hat and sunglasses should also be worn alongside the shirt for complete sun protection.
Shoes: For muddy conditions, you should wear shoes with good traction and waterproof capabilities. Here are some good options:
**Boots**: Waterproof boots with thick soles provide excellent protection and grip. Look for boots with textured or aggressive tread patterns.
**Hiking boots**: These typically have sturdy construction, good ankle support, and aggressive treads designed for rough terrain.
**Work boots**: Heavy-duty work boots often have slip-resistant soles and waterproof materials.
**Waterproof sneakers**: Some sneakers are designed to be waterproof and have good grip, though they may not be as durable as boots.
Key features to look for:
- Waterproof or water-resistant materials
- Non-slip sole with deep tread
- Good ankle support
- Durable construction
- Quick-drying materials
Avoid regular sneakers or dress shoes in muddy conditions, as they'll get soaked and provide poor traction.
Finished in 40.581 seconds
With Async Futures
Now let's run with futures, note you have to access the result
attribute of the futures to get to the returned value.
Warning
We recommend you postfix your futures with _future
to avoid naming conflicts and confusion.
from time import perf_counter
from dandy import Bot
start_time = perf_counter()
pants_intel_future = Bot().process_to_future('What type of pants should I wear in the rain?')
shirt_intel_future = Bot().process_to_future('What type of shirt should I wear in the sun?')
shoes_intel_future = Bot().process_to_future('What type of shoes should I wear in the mud?')
print('Pants: ' + pants_intel_future.result.content)
print('Shirt: ' + shirt_intel_future.result.content)
print('Shoes: ' + shoes_intel_future.result.content)
print(f'Finished in {perf_counter() - start_time:.3f} seconds')
Pants: For muddy conditions, you should wear shoes with good traction and waterproof capabilities. Here are some options:
**Boots**: Tall boots or waterproof boots with rubber soles provide excellent protection from mud and water. They also offer ankle support.
**Hiking boots**: These typically have aggressive tread patterns on the soles that help grip muddy surfaces and prevent slipping.
**Work boots**: Heavy-duty work boots with slip-resistant soles are great for muddy conditions, especially if you're doing manual labor.
**Waterproof shoes**: If you don't need full boots, waterproof sneakers or shoes with good sole grip will work well.
Key features to look for:
- Rubber or textured soles for traction
- Waterproof materials
- Good ankle support
- Quick-drying materials
Avoid regular leather shoes or thin-soled sneakers as they'll get soaked and slippery in mud.
Shirt: For muddy conditions, you should wear shoes with the following features:
**Boot-style shoes** - Tall boots or waterproof boots provide the best protection and traction. They keep mud from entering the shoe and offer better ankle support.
**Non-slip soles** - Look for shoes with aggressive tread patterns or rubber soles designed for muddy conditions. Some boots have special lug patterns that grip mud and slippery surfaces.
**Waterproof materials** - Leather or synthetic waterproof shoes prevent water from seeping in and keep your feet dry. Avoid canvas or fabric shoes that will get soaked and heavy in mud.
**Secure fit** - Make sure the shoes fit snugly but aren't too tight, as mud can make feet swell. Laces or straps help keep the shoe secure on your foot.
**Easy to clean** - Choose shoes that are easy to rinse off mud, such as those with smooth surfaces or removable insoles.
If you're doing heavy work in mud, consider waterproof hiking boots or work boots with good ankle support. For light walking, sturdy waterproof sneakers or rain boots can work well.
Shoes: For muddy conditions, you should wear shoes with good traction and drainage. Here are some good options:
**Boots**: Waterproof boots with rubber soles provide excellent grip on muddy surfaces. They also keep your feet dry.
**Hiking boots**: These typically have aggressive tread patterns and waterproof materials that handle mud well.
**Work boots**: Heavy-duty work boots with slip-resistant soles are great for muddy environments.
**Sneakers with good grip**: If you're just walking through light mud, sneakers with textured soles can work, but they won't be as effective as dedicated muddy footwear.
Key features to look for:
- Rubber or textured soles for traction
- Waterproof materials
- Good ankle support
- Easy to clean
Avoid sandals or smooth-soled shoes, as they'll make walking difficult and potentially dangerous in muddy conditions.
Finished in 13.484 seconds
Advanced Async
Sometimes in more complex situations you might need to cancel a future or set a timeout.
from dandy import Bot
user_likes_scary_animals = True
cute_animal_future = Bot().process_to_future('Can you tell me about a random cute animal?')
scary_animal_future = Bot().process_to_future('Can you tell me about a random scary animal?')
scary_animal_future.set_timeout(seconds=30)
if user_likes_scary_animals:
cute_animal_future.cancel()
print(scary_animal_future.result.content)
The deathworm is a terrifying creature from the desert regions of the American Southwest. Despite its name, it's not actually a worm but a massive, snake-like predator that can grow up to 20 feet long. Deathworms live in deep burrows and are completely blind, navigating through their environment using sensitive tentacles on their heads.
These creatures are incredibly dangerous because they're ambush predators that can strike with lightning speed. They have powerful constricting abilities and their bite can be fatal to humans. Deathworms are also known for their ability to survive in extreme heat and can go months without food.
The most chilling aspect of deathworms is their hunting behavior - they wait patiently in their burrows, sensing vibrations from passing prey, then launch themselves out with incredible force to capture anything that comes within range. Their presence in desert areas has been documented by various explorers and survivalists who have narrowly escaped encounters with these deadly creatures.