Comments (1)
Hi @vjcspy
For extra information you can refer to @dbrattli 's reply on an older issue
That issue being from v3 times, below is a sample code that should get you the expected parallelism.
def main():
import time
import reactivex
from reactivex import operators as ops
from reactivex.scheduler import ThreadPoolScheduler
start = time.time()
pool_scheduler = ThreadPoolScheduler(5)
messages = []
def log(message):
with threading.Lock():
messages.append(f"{round(time.time() - start , 1)}: {message}")
def intense_calculation(value):
time.sleep(2)
return f"Computed for {value}"
# Create an Observable
source = reactivex.from_(["Alpha", "Beta", "Gamma"])
source.pipe(
ops.flat_map(lambda s: reactivex.from_future(pool_scheduler.executor.submit(intense_calculation, s))),
).subscribe(
on_next=lambda s: log(
f"Processed {s} on {threading.current_thread().name}"
),
on_error=lambda e: log(f"ERROR {e}"),
on_completed=lambda: log("Process complete!"),
)
time.sleep(3)
log("End")
print(messages)
Additional issues that discuss this: #67
Hope this helps
from rxpy.
Related Issues (20)
- [Question] shiping data between asyncio and rxpy HOT 1
- [Question] Reading/writing from/to a Pandas DataFrame in rxpy HOT 2
- [TESTING] Notification equality uses string representation HOT 2
- Cannot pickle reactive classes
- unexpected behaviour regarding item count HOT 2
- Zip operator does not work HOT 3
- Rolling throttle operator
- reactivex.timer emits immediately on second subscription HOT 1
- Unexpected results of switch_map operator HOT 1
- Verson number in GitHub release is 0.0.0
- [BUG] buffer_with_time_or_count lost some data HOT 1
- [BUG] buffer_with_time_or_count loses data
- Python 3.12 deprecates timezone non aware utcfromtimestamp() and utcnow()
- This is a concurrent library, but not thread safe?
- AsyncIOScheduler.schedule is not thread safe!
- RxPY/ example / timer.py broken: Future is not iterable
- switch_map() operator not listed in documentation
- `operators.retry(n)` interferes with non-erroring repeats
- Questions about Copilot + Open Source Software Hierarchy
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rxpy.