Discussion:
[libtorrent] Displaying multiple torrent download information on terminal
Ronald Degmar
2017-02-20 03:29:04 UTC
Permalink
Hello,

I managed to display information about multiple torrent downloads by using
urdwid python library
http://urwid.org/

However, I need to do a few unit test cases by utilizing only linux
terminal window.

How could I display download information of the multiple torrents by just
printing to the terminal?

In the libtorrent examples, there are sample clients, but they just deal
with one torrent file at the time and need to finish it
in order to display information about the next one.

I tried writing one python thread for each torrent in the torrent handler,
but this doesn't work as you know the libtorrent session is already a single
thread and cannot be split.

What would be the way to go, so I don't break libtorrent thread session?

Thanks,

Ronald Barrios
Arvid Norberg
2017-02-20 15:50:30 UTC
Permalink
Post by Ronald Degmar
[...]
In the libtorrent examples, there are sample clients, but they just deal
with one torrent file at the time and need to finish it
in order to display information about the next one.
I tried writing one python thread for each torrent in the torrent handler,
but this doesn't work as you know the libtorrent session is already a single
thread and cannot be split.
Both the session and torrent_handle objects support access from multiple
threads. However, I don't see how using multiple threads would solve your
problem.
Post by Ronald Degmar
What would be the way to go, so I don't break libtorrent thread session?
Call add_torrent multiple times. Call session::get_torrent_status()
periodically and print out the information you get back.

http://libtorrent.org/reference-Core.html#get_torrent_status()

Once you want your program to scale better, and not constantly poll for
changes, you can start calling session::post_torrent_updates() instead,
which will post an alert containing only status of torrent's whose counters
have changed since last time. This would require you to keep a copy of the
stats you're interested in and update it.

http://libtorrent.org/reference-Core.html#post_torrent_updates()
--
Arvid Norberg
Ronald Degmar
2017-02-20 23:24:53 UTC
Permalink
Hi Arvid,

Threads are working!!!
Here is the python code I used:

*def process_handles(self, handles):*

* for h in handles:*
* six.print_('starting', h.name <http://h.name/>())*
* t = threading.Thread(target=self.query_handle, args=(h,))*
* t.start()*

And I didn't call the session::get_torrent_status() or the
session::post_torrent_updates().
*Do I need to? I mean I just used "h.status()"*

Next question is about another different topic. It may be a good idea to
improve libtorrent to work with CUDA GPU and to stream media
libtorrent-P2P-based.
Have you thought about that?

Ronald Barrios
Post by Ronald Degmar
Post by Ronald Degmar
[...]
In the libtorrent examples, there are sample clients, but they just deal
with one torrent file at the time and need to finish it
in order to display information about the next one.
I tried writing one python thread for each torrent in the torrent
handler,
Post by Ronald Degmar
but this doesn't work as you know the libtorrent session is already a single
thread and cannot be split.
Both the session and torrent_handle objects support access from multiple
threads. However, I don't see how using multiple threads would solve your
problem.
Post by Ronald Degmar
What would be the way to go, so I don't break libtorrent thread session?
Call add_torrent multiple times. Call session::get_torrent_status()
periodically and print out the information you get back.
http://libtorrent.org/reference-Core.html#get_torrent_status()
Once you want your program to scale better, and not constantly poll for
changes, you can start calling session::post_torrent_updates() instead,
which will post an alert containing only status of torrent's whose counters
have changed since last time. This would require you to keep a copy of the
stats you're interested in and update it.
http://libtorrent.org/reference-Core.html#post_torrent_updates()
--
Arvid Norberg
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Libtorrent-discuss mailing list
https://lists.sourceforge.net/lists/listinfo/libtorrent-discuss
Arvid Norberg
2017-02-22 01:18:19 UTC
Permalink
Post by Ronald Degmar
Hi Arvid,
Threads are working!!!
*def process_handles(self, handles):*
* for h in handles:*
* six.print_('starting', h.name <http://h.name/>())*
* t = threading.Thread(target=self.query_handle, args=(h,))*
* t.start()*
And I didn't call the session::get_torrent_status() or the
session::post_torrent_updates().
*Do I need to? I mean I just used "h.status()"*
It would be a lot more efficient to have a single thread that queries and
prints the torrent status. in which case it would also be more efficient to
have a single query for all statuses, instead of one call per
torrent_handle.

you don't need to call post_torrent_updates(), it's just more efficient.
Post by Ronald Degmar
Next question is about another different topic. It may be a good idea to
improve libtorrent to work with CUDA GPU and to stream media
libtorrent-P2P-based.
Have you thought about that?
Which computation specifically do you suggest offloading the a GPU?
--
Arvid Norberg
Ronald Degmar
2017-02-22 02:37:25 UTC
Permalink
Yes, actually there's another code type much simpler I guess:

*while (any(not hand.is_seed() for hand in handles)):*
* ...*
* for h in handles:*
* s = h.status()*
* ...*

And for the GPU: In CUDA programming we work under the grid, block, threads
schema. The grid contains the blocks, and a block contains the threads.
Each thread would be in charge to download a piece or chunk of information.
Well, I'm not making an assertion that this must be possible in some way,
just throwing some ideas.

Ronald
Post by Arvid Norberg
Post by Ronald Degmar
Hi Arvid,
Threads are working!!!
*def process_handles(self, handles):*
* for h in handles:*
* six.print_('starting', h.name <http://h.name/>())*
* t = threading.Thread(target=self.query_handle, args=(h,))*
* t.start()*
And I didn't call the session::get_torrent_status() or the
session::post_torrent_updates().
*Do I need to? I mean I just used "h.status()"*
It would be a lot more efficient to have a single thread that queries and
prints the torrent status. in which case it would also be more efficient to
have a single query for all statuses, instead of one call per
torrent_handle.
you don't need to call post_torrent_updates(), it's just more efficient.
Post by Ronald Degmar
Next question is about another different topic. It may be a good idea to
improve libtorrent to work with CUDA GPU and to stream media
libtorrent-P2P-based.
Have you thought about that?
Which computation specifically do you suggest offloading the a GPU?
--
Arvid Norberg
------------------------------------------------------------
------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Libtorrent-discuss mailing list
https://lists.sourceforge.net/lists/listinfo/libtorrent-discuss
Loading...