Comments (7)
AttributeError: Can't pickle local object 'FuturesSession.request..wrap'
Hrm. That looks like it's failing to pickle the wrapper function. I don't imagine it's possible to pickle functions, but can't say that it's something I've directly looked into.
You might look into the built in requests callback stuff, http://docs.python-requests.org/en/master/user/advanced/#event-hooks. To be honest if I had it to do over I wouldn't add the background_callback stuff here as I think those hooks would be a better way to do most of what you would do in them anyway.
from requests-futures.
Great, thank you for the help! Using the built in hooks system I was able to get what Iād wanted to done (just background parsing of json). The one catch is I ran into issues with actually passing the information back out, I believe due to how the response is pickled and moved between processes. I ended up saying response.elapsed = response.json(). I chose this field as it was actually modifiable, and the other fields were not. Trying to add a new field to the response resulted in the data being lost when using a processpool, although it worked fine with a threadpool.
from requests-futures.
Trying to add a new field to the response resulted in the data being lost when using a processpool, although it worked fine with a threadpool.
Funky & good to know. I think i'm going to go ahead and deprecate background_callback
itself and point people towards the callbacks. Sounds like they're workable with processes and they should be a drop-in replacement and better option for threadpools.
from requests-futures.
Hello! I have the latest version and getting a similar error when trying to use your advanced example for the hooks - AttributeError: Can't pickle local object 'ElapsedFuturesSession.request..timing'
class ElapsedFuturesSession(FuturesSession):
def request(self, method, url, hooks={}, *args, **kwargs):
start = time()
def timing(r, *args, **kwargs):
r.elapsed = time() - start
try:
if isinstance(hooks['response'], (list, tuple)):
# needs to be first so we don't time other hooks execution
hooks['response'].prepend(timing)
else:
hooks['response'] = [timing, hooks['response']]
except KeyError:
hooks['response'] = timing
return super(ElapsedFuturesSession, self) \
.request(method, url, hooks=hooks, *args, **kwargs)
My main goal here is to track the time it takes to send a request to a downstream. I also seen another attribute error, but I believe the above issue is the main concern.
hooks['response'].prepend(timing)
AttributeError: 'list' object has no attribute 'prepend'
Thoughts? Or suggestions?
Thanks!
from requests-futures.
AttributeError: 'list' object has no attribute 'prepend'
Too many languages with slight diffs and not enough example testing. Looks like I didn't hit that case of the code. That line should be
hooks['response'].insert(0, timing)
Will get the readme updated. Thanks.
from requests-futures.
Thank you!
from requests-futures.
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.
from requests-futures.
Related Issues (20)
- OSError Issues when used within celery task (gevent) HOT 2
- Adding attribute to response via hook (as seen in examples) fails HOT 1
- Cannot switch to a different thread HOT 3
- Possibility to accept old SSL versions? HOT 1
- Problem with data field in header request HOT 1
- Making a future request and letting callback work with result - some are missing HOT 2
- Error When there is a large parallel Requests go. HOT 2
- Provide wheels on PyPI HOT 1
- How do we pass arguments to the hooks? HOT 3
- AttributeError: 'Future' object has no attribute 'status_code' HOT 1
- 1.0.0: missing git tag HOT 5
- Response for batched requests HOT 6
- Add type annotations HOT 4
- Not showing as updated on PyPI HOT 3
- On exception it returns xx (Caused By None), whereas the requests module returns xx (Caused By xx) HOT 4
- The elapsed time hook example does not work HOT 3
- 1.0.0: pytest is failing in two units HOT 6
- Use pytest-httpbin? HOT 8
- Attribute set via response hooks does not work with ProcessPoolExecutor HOT 4
- RFE: preserve contextvars when performing the request HOT 1
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 requests-futures.