Comments (5)
Sure! To prove to myself that adding pooling would make the difference for me I created a MyAsyncImage/myasyncimage.py so that I could make it load my hacky MyLoader/myloader.py rather than the Kivy code one. It was basically copy/paste, apart from the changes indicated below.
This was just a test, I'm sure it needs more thought than this.
...
import urllib3
pool_mgr = urllib3.PoolManager(maxsize=10)
"""
Note: I set maxsize to 10 because I was getting warnings due to too many concurrent requests:
[WARNING] [Connection pool is full, discarding connection]
I tested this with a value of 1000 also with seemingly no ill effect.
Maybe it should match the Loader.num_workers value?
It's set to 10 in my case as the images I am loading are rather small.
I left num_pools unchanged as not relevant in my case: there was only ever going to be 1 pool,
namely the connection to my image server. (default is 10)
"""
Cache.register('kv.loader', limit=500, timeout=500)
...
def _load_urllib(self, filename, kwargs):
'''(internal) Loading a network file. First download it, save it to a
temporary file, and pass it to _load_local().'''
import tempfile
global pool_mgr
if not pool_mgr:
pool_mgr = urllib3.PoolManager(maxsize=10)
...
try:
_out_filename = ''
"""
Note: in my hacked version I removed a whole section here about smb,
headers, custom context as not relevant to my test
"""
fd = pool_mgr.request("GET", filename)
if '#.' in filename:
# allow extension override from URL fragment
suffix = '.' + filename.split('#.')[-1]
else:
ctype = fd.headers['Content-Type']
...
idata = fd.data
# removed: fd.close()
# removed: fd = None
...
from kivy.
I am working on a refactor of loader.py in the background, so listening with interest. Do you want to share the changes you tried?
from kivy.
And how it behave when you change default network backend to "requests"? Its single line in config file
Can someone benchmark it?
from kivy.
The loader.py
currently doesn't use the config file settings (apart from user agent) -- urlib.request
is hardcoded.
There is no session mechanism for the "requests" implementation, so that shouldn't make a difference?
On my app I make several requests to my API on start up, I had a huge efficiency boost after I implemented sessions for that.
Currently, I create a session in my App class, save it as a class attribute and then pass the session object as an argument to e.g. my API request module. It works fine but seems a bit hacky to do it this way.
There might be scope to handle this better?
from kivy.
The
loader.py
currently doesn't use the config file settings (apart from user agent) --urlib.request
is hardcoded.There is no session mechanism for the "requests" implementation, so that shouldn't make a difference?
On my app I make several requests to my API on start up, I had a huge efficiency boost after I implemented sessions for that.
Currently, I create a session in my App class, save it as a class attribute and then pass the session object as an argument to e.g. my API request module. It works fine but seems a bit hacky to do it this way.
There might be scope to handle this better?
it uses
Try
Config.set("network", "implementation", "requests")
it should work from kivy 2.2.0
kivy/kivy/network/urlrequest.py
Line 781 in 340ea0d
from kivy.
Related Issues (20)
- Webview widget
- All my programs show nothing on WIndows 11 (after connecting a second screen using an adapter) HOT 7
- Label widget draw using the 'color' instead of 'disabled_color' HOT 4
- Kivy does not work at all (seg faults) on MacOS HOT 11
- pytube to download YouTube video works on notebook but fails on kivy app HOT 1
- Graphics: Storing `_points` for `Smooth*` implementations result in a performance drop even on non-smooth drawings HOT 11
- Migrate `SDL2` to `SDL3` HOT 3
- AnchorLayout prevents child widgets from controlling their height
- An unbound event before ScrollView is triggered
- CompoundSelectionBehavior.deselect_node() should not silently hide exceptions
- Unexpected behavior by TypeError in `query_xinput` method
- `DDSFile.save` raise a type error by invalid write HOT 1
- `Tool.write_tex` raises a type error by invalid write
- `ConfigParser.write` takes 1 positional argument but 2 were given HOT 2
- Add support for wl-clipboard for Linux
- `im.add_mipmap` requires five parameters, but only four arguments are being used
- Dependency Dashboard
- Investigate an alternative for `no-response` bot
- Pyinstaller package required `LD_PRELOAD` to start on Linux HOT 1
- `disable_multitouch` should also disable MTD loading on Linux
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 kivy.