import requests
from Pythine import Pythine
@Pythine.map(thread_num=5)
def slow_network(url, timeout=1):
return requests.get(url, timeout=timeout).text
slow_network([
'http://www.google.com',
'http://www.microsoft.com',
'http://www.facebook.com'
] * 30)
The slow_network
function will be automatically paralleled in 5
threads.
Run in your bash
pip install Pythine
And it's enough to get Pythine in your box.
Pythine will parallel your function in CPU threads, which only benefits from heavy-job parallelism. So if your function is very efficient, e.g.
def add(a):
return a+1
, Pythine will definitely slow down the process!
However, we are still working on accelerate this case.
So please only Pythine the heavy-job function.
The reason might be:
- (Highly possible) You need to make the function you want to Pythine threaded-safe. Sometimes the write conflict can cause a mess.
- To be continued!
- Try to make parallelism more efficient. e.g. if the user give a large list to map, we partition the task list to sub-task lists to make each thread task heavier, which will benefit more from multi-threaded.
You're more than welcome to contribute by forking this repo and sending pull requests! Although we believe the concept in Pythine is very charming, the Pythine is still not perfect. We're continuously working on improving it.