[Bf-python] Best way for add-on to download with Python

Dalai Felinto dfelinto at gmail.com
Thu Jan 24 04:18:00 CET 2013


Hi Peter,

First things first, I can't see how modal would help you. I think a handler
is the way to go if you want a python function to run in parallel to the
blender main operations.

This function cannot block the main thread though (the problem as you
described) so you need a threaded way of getting this data.

Now, I don't know how "far" you want to go, but have you considered direct
socket connections?

In my experience with client/server UDP communications (not necessarily the
TCP you have to deal with in your downloads, but it may apply) it's pretty
doable to implement a "non-preemptive multithreading" system to offload the
main process.

The idea is inspired in the way Lua implements multithreading (or better,
the way Lua doesn't do it ;) with coroutines [1].

What I found out is that most socket connections are buffered in the OS
end. So as long as you get back from time to time to see if the buffer is
emptied, you are good to go.

If that helps you can find a code snippet here [2]. This code considers the
end of a package whenever it finds a "\n", but I'm sure you can adapt it to
whatever the HTTP transferring does.

[1] - http://www.lua.org/pil/9.4.html
[2] - http://www.pasteall.org/39081/python
(start looking at the init and loop functions and go from there)

Good luck,
Dalai

blendernetwork.org/member/dalai-felinto
www.dalaifelinto.com


2013/1/23 Peter D. Cassetta <peter at fingertipsoft.com>

>
> Another suggestion, which I feel would be preferable if I could get it
> working solely or mostly with Python, was to start another process.
> While I'm unsure exactly how one would do this, I got the impression
> that it might be possible to open a separate Python console, or launch
> another Blender instance (preferably in the background), and download
> needed files from there without slowing down anything else in the first
> Blender instance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20130123/60bb8252/attachment.html>


More information about the Bf-python mailing list