Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gphat/experiment-python
Python experiments inspired by GitHub's dat-science
https://github.com/gphat/experiment-python
Last synced: 13 days ago
JSON representation
Python experiments inspired by GitHub's dat-science
- Host: GitHub
- URL: https://github.com/gphat/experiment-python
- Owner: gphat
- Created: 2014-10-11T19:14:37.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-10-20T01:44:56.000Z (about 10 years ago)
- Last Synced: 2023-04-13T00:45:52.483Z (over 1 year ago)
- Language: Python
- Size: 133 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Experiment is a Python module inspired by GitHub's [dat-science](https://github.com/github/dat-science).
It uses a Python's [futures](https://pypi.python.org/pypi/futures).
# Overview
Experiment takes two Futures and executes both using a ThreadPoolExecutor. The
`Experiment` object itself is a future that will be completed when the control
finishes. The `result` of this Future is the output of the control Future! This
way you get your results as quickly as the control finishes.You can also call `get_future` on the `Experiment` to get a Future that covers
the completion of the the control *and* the experiment!# Usage
```python
from experiment import Experimentdef old_func():
# Do things the old waydef new_func():
# Do things the new way# Conduct an experiment where control is your old
# code path and experiment is the new!
exp = Experiment(
control = old_func,
experiment = new_func
)# The returned experiment is a Future. You can get the result,
# which will be the result of the control!# Send this back!
control = exp.result()# You can also get a future that covers *both* the control and
# the experiment to verify that they match.total_result = exp.get_future().result()
if(total_result.matches()):
print "Yay!"
else:
# Here's the control's result (it's a Future!)
print total_result.get_control_result().result()
# And the experiment, also a Future!
print total_result.get_experiment_result().result()
```