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 your best options:
**Rain Pants/Outerwear**: Waterproof rain pants or waterproof outer pants with a waterproof coating or membrane (like Gore-Tex) are ideal. These are designed specifically for wet conditions.
**Waterproof Materials**: Look for pants made from waterproof fabrics such as synthetic materials, treated cotton, or waterproof nylon. Avoid regular denim or untreated cotton, which will absorb water and become heavy.
**Water-Resistant Options**: If you don't have waterproof pants, water-resistant pants (which repel water but aren't fully waterproof) can work in light rain. These are often made from treated fabrics or have a water-repellent finish.
**Avoid**: Regular jeans, cotton pants, or any untreated fabric that will soak up water and stay wet. These will make you feel cold and uncomfortable.
**Additional Tips**: Consider wearing moisture-wicking base layers underneath to keep your skin dry, and ensure the pants have good ventilation to prevent overheating while staying dry.
The key is choosing pants that either repel water or are specifically designed to be waterproof for the best protection in rainy conditions.
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, loose-fitting clothes as they offer less protection - instead choose fitted or slightly loose clothing that covers your arms and torso. Some specialized sun shirts also have built-in UV protection and are designed specifically for outdoor activities. Don't forget to wear a wide-brimmed hat and sunglasses to protect your face, neck, and eyes as well.
Shoes: For muddy conditions, you should wear shoes with good traction and waterproof capabilities. Here are some good options:
**Boots**: Waterproof boots with rubber or synthetic materials work best. They keep your feet dry and provide ankle support.
**Hiking boots**: These typically have aggressive tread patterns and waterproof membranes that handle mud well.
**Work boots**: Heavy-duty boots with slip-resistant soles are excellent for muddy terrain.
**Waterproof shoes**: Look for shoes labeled as waterproof or water-resistant, often with Gore-Tex lining.
Key features to look for:
- Non-slip sole patterns (deep tread)
- Waterproof materials
- Good ankle support
- Quick-drying properties
- Breathable fabrics
Avoid regular sneakers or dress shoes in muddy conditions as they'll get soaked and provide poor traction.
Finished in 4.287 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 rainy weather, you should wear pants made from waterproof or water-resistant materials. Here are your best options:
1. **Rain pants or waterproof pants** - These are specifically designed for wet conditions and often have waterproof membranes or coatings
2. **Waterproof trousers** - Made with waterproof fabrics like Gore-Tex or similar materials
3. **Nylon or polyester pants** - These synthetic fabrics repel water and dry quickly
4. **Waterproof cotton blends** - Some cotton pants are treated to be water-resistant
5. **Jeans or thick cotton pants** - While not fully waterproof, they can handle light rain if you're quick to get indoors
Avoid regular cotton pants, as they absorb water and become heavy and uncomfortable when wet. Also avoid leather or suede pants, as these can be damaged by moisture.
If you're going to be out in the rain for an extended period, invest in proper waterproof pants rather than trying to make regular pants work.
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 can't find a UPF shirt, opt for tightly woven synthetic fabrics or treat regular clothing with UV-protective sprays. 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 drainage. Here are the best options:
**Boots**: Waterproof boots with rubber or synthetic materials work well. They keep your feet dry and provide ankle support.
**Hiking boots**: These offer excellent grip with aggressive tread patterns and are designed for rough terrain.
**Work boots**: Heavy-duty boots with steel toes or puncture resistance are great for muddy environments.
**Waterproof shoes**: Look for shoes with waterproof membranes like Gore-Tex that prevent water from entering while allowing moisture to escape.
**Key features to look for**:
- Non-slip soles with deep tread patterns
- Quick-drying materials
- Good ankle support
- Waterproof construction
- Breathable fabrics
Avoid regular sneakers or dress shoes in muddy conditions, as they'll get soaked and provide poor traction. The key is having shoes that can handle wet, slippery surfaces while keeping your feet protected and dry.
Finished in 1.516 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=5)
if user_likes_scary_animals:
cute_animal_future.cancel()
print(scary_animal_future.result.content)
The death worm, also known as the sandworm or desert worm, is a terrifying creature that supposedly lives in the Sahara Desert. Despite its name, it's not actually a worm but a massive predatory arthropod that can grow up to 10 feet long. These creatures are believed to live buried underground in the sand, waiting for prey to pass above before lunging out with their powerful claws and venomous stingers. Local desert tribes have long warned travelers about these creatures, describing them as silent hunters that can completely devour a camel or even a human. The death worm's most frightening aspect is its ability to remain hidden underground for months at a time, making it nearly impossible to detect or avoid. Some accounts claim the creature can even create small sand whirlwinds as it moves through the desert, leaving behind only mysterious signs of its passage.