Add set_alert_notify to python bindings (#3066)

This commit is contained in:
Andrew Resch 2018-05-29 13:30:59 -07:00 committed by Arvid Norberg
parent 6c4869f044
commit c2ea38fdfe
2 changed files with 28 additions and 0 deletions

View File

@ -388,6 +388,20 @@ namespace
}
#endif // TORRENT_ABI_VERSION
void alert_notify(object cb)
{
lock_gil lock;
if (cb)
{
cb();
}
}
void set_alert_notify(lt::session& s, object cb)
{
s.set_alert_notify(std::bind(&alert_notify, cb));
}
alert const*
wait_for_alert(lt::session& s, int ms)
{
@ -987,6 +1001,7 @@ void bind_session()
.def("save_state", &save_state, (arg("entry"), arg("flags") = 0xffffffff))
.def("pop_alerts", &pop_alerts)
.def("wait_for_alert", &wait_for_alert, return_internal_reference<>())
.def("set_alert_notify", &set_alert_notify)
.def("add_extension", &add_extension)
#if TORRENT_ABI_VERSION == 1
#if TORRENT_USE_I2P

View File

@ -15,6 +15,7 @@ import subprocess as sub
import sys
import inspect
import pickle
import threading
# include terminal interface for travis parallel executions of scripts which use
# terminal features: fix multiple stdin assignment at termios.tcgetattr
@ -398,6 +399,18 @@ class test_alerts(unittest.TestCase):
print(a.message())
time.sleep(0.1)
def test_alert_notify(self):
ses = lt.session(settings)
event = threading.Event()
def callback():
event.set()
ses.set_alert_notify(callback)
ses.async_add_torrent(
{"ti": lt.torrent_info("base.torrent"), "save_path": "."})
event.wait()
class test_bencoder(unittest.TestCase):