This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Can ktorrent script respond to quit event?

Tags: None
(comma "," separated)
ogcub
Registered Member
Posts
3
Karma
0
Ktorrent doesn't like removable storage. It complains that files doesn't exist, then they are on removable drive, which isn't always mounted. So I need to stop certain torrents on system shutdown, then ktorrent is quitting. However, there seems to be no callbacks provided for such events.
Or maybe, there is some way too suppress file missing dialogues on startup and automatically stop those torrents?

I'am using ktorrent 3.3.4 from kubuntu 10.04
Thanks for advice
George
Moderator
Posts
5421
Karma
1
If your script has an unload function it will be called when the script is unloaded, all scripts will be unloaded on exit:

http://ktorrent.org/wiki/index.php/Writ ... ts#Cleanup

Regarding, the fundamental problem of removable storage, it is my intention in 4.1 to add some mechanism to keep track of removable storage, and not start torrents when the storage is not mounted.
ogcub
Registered Member
Posts
3
Karma
0
Thank you.
this script did the trick
#!/usr/bin/env kross
# -*- coding: utf-8 -*-
import KTorrent
import os
import re
import KTScriptingPlugin
import Kross
#from PyQt4 import QtCore

t = Kross.module("kdetranslation")

class AutoResume:
def __init__(self):
self.auto_resume = False
self.hours = 0
self.minutes = 1
self.seconds = 0
self.timer = KTScriptingPlugin.createTimer(True)
self.timer.connect('timeout()',self.timerFired)
KTorrent.log("Hack: init done")


def timerFired(self):
if not os.access("/media/disk-1/", os.F_OK):
return

try:
KTorrent.startAll()
KTorrent.log("Hack: all started")
self.timer.stop()
except:
KTorrent.log("Hack: some err")


def startTimer(self):
self.timer.start((self.hours * 3600 + self.minutes * 60 + self.seconds)*1000)

def save(self):
pass

def load(self):
self.startTimer()


def configure(self):
pass



ar = AutoResume()
ar.load()

def configure():
global ar
ar.configure()

def unload():
global ar
del ar
tors = KTorrent.torrents()
for t in tors:
tor = KTorrent.torrent(t)
if re.match("^/media/disk-1/", tor.dataDir()):
KTorrent.stop(t)
KTorrent.log("Hack: Stopping torrent: "+ str(tor.name()))


Also ktorrent crashes if external storage is unplugged while data is read.
George
Moderator
Posts
5421
Karma
1
Have you got a backtrace of the crash ?
ogcub
Registered Member
Posts
3
Karma
0
it's not very hard to reproduce. See if it helps
Code: Select all
Application: KTorrent (ktorrent), signal: Bus error
[Current thread is 1 (Thread 0xb4ec1710 (LWP 1895))]

Thread 5 (Thread 0xae9e3b70 (LWP 2169)):
#0  0xb77c0430 in __kernel_vsyscall ()
#1  0xb5b6f6d6 in gettimeofday () from /lib/tls/i686/cmov/libc.so.6
#2  0xb76b6bd6 in bt::Now() () from /usr/lib/libbtcore.so.12
#3  0xb76cba7a in ?? () from /usr/lib/libbtcore.so.12
#4  0xb76cc6b8 in ?? () from /usr/lib/libbtcore.so.12
#5  0xb688b32e in ?? () from /usr/lib/libQtCore.so.4
#6  0xb67fd96e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#7  0xb5bb3a0e in clone () from /lib/tls/i686/cmov/libc.so.6

Thread 4 (Thread 0xae1e2b70 (LWP 2170)):
#0  0xb77c0430 in __kernel_vsyscall ()
#1  0xb6802015 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/tls/i686/cmov/libpthread.so.0
#2  0xb688c287 in QWaitCondition::wait(QMutex*, unsigned long) () from /usr/lib/libQtCore.so.4
#3  0xb76cb3a9 in ?? () from /usr/lib/libbtcore.so.12
#4  0xb76cc6b8 in ?? () from /usr/lib/libbtcore.so.12
#5  0xb688b32e in ?? () from /usr/lib/libQtCore.so.4
#6  0xb67fd96e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#7  0xb5bb3a0e in clone () from /lib/tls/i686/cmov/libc.so.6

Thread 3 (Thread 0xad9e1b70 (LWP 2171)):
#0  0xb77c0430 in __kernel_vsyscall ()
#1  0xb6802015 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib/tls/i686/cmov/libpthread.so.0
#2  0xb688c287 in QWaitCondition::wait(QMutex*, unsigned long) () from /usr/lib/libQtCore.so.4
#3  0xb76cfbaa in ?? () from /usr/lib/libbtcore.so.12
#4  0xb688b32e in ?? () from /usr/lib/libQtCore.so.4
#5  0xb67fd96e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#6  0xb5bb3a0e in clone () from /lib/tls/i686/cmov/libc.so.6

Thread 2 (Thread 0xb3882b70 (LWP 2838)):
#0  0xb52c77cf in g_main_context_check () from /lib/libglib-2.0.so.0
#1  0xb52c80ce in ?? () from /lib/libglib-2.0.so.0
#2  0xb52c84b8 in g_main_context_iteration () from /lib/libglib-2.0.so.0
#3  0xb69b960f in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#4  0xb698c059 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#5  0xb698c4aa in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/libQtCore.so.4
#6  0xb68885a8 in QThread::exec() () from /usr/lib/libQtCore.so.4
#7  0xb696bc1b in ?? () from /usr/lib/libQtCore.so.4
#8  0xb688b32e in ?? () from /usr/lib/libQtCore.so.4
#9  0xb67fd96e in start_thread () from /lib/tls/i686/cmov/libpthread.so.0
#10 0xb5bb3a0e in clone () from /lib/tls/i686/cmov/libc.so.6

Thread 1 (Thread 0xb4ec1710 (LWP 1895)):
[KCrash Handler]
#6  0xb5b5afe1 in ?? () from /lib/tls/i686/cmov/libc.so.6
#7  0xb7735006 in bt::Chunk::readPiece(unsigned int, unsigned int, unsigned char*) () from /usr/lib/libbtcore.so.12
#8  0xb76e8eea in ?? () from /usr/lib/libbtcore.so.12
#9  0xb76e53bf in ?? () from /usr/lib/libbtcore.so.12
#10 0xb76e3a04 in ?? () from /usr/lib/libbtcore.so.12
#11 0xb7707df8 in ?? () from /usr/lib/libbtcore.so.12
#12 0xb77119c1 in bt::TorrentControl::update() () from /usr/lib/libbtcore.so.12
#13 0x08071a63 in _start ()
George
Moderator
Posts
5421
Karma
1
That crash is fixed in 4.0


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]