the forums at degreez.net

It is currently Thu Apr 25, 2024 4:19 am

All times are UTC - 7 hours [ DST ]




Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
PostPosted: Mon Feb 07, 2005 11:28 pm 
hi!

I wrote some scripts to launch btlaunchmanycurses in a screen at startup with pidfile and all etc., so it kind of resembles a bittorrentd, which is nice to have.

However, does anyone know if there is a chance to shut down btlaunchmanycurses gracefully except hitting C-c, because apparantly SIGINT (2) is NOT the same as C-c to the application. I tried lots of different signals but btlaunchmanycurses simply dies, which forces the hash check at the next start and also makes some trackers hate me, because they believe I still have their torrents open, since I did not terminate the connection correctly.

Any ideas?


Top
  
 
 Post subject: gracefull shutdown
PostPosted: Mon Feb 14, 2005 9:37 pm 
Imho the only way is to patch the python code. I briefly looked over it, but couldn't find the right place for a shutdown. Maybe in some exception handler...


Top
  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 11:47 am 
Well, thanks for looking

I was currently trying to send a 'q' or a 'C-c' to the screen container via the named pipe in /var/run/screen. However, I can't figure out how to do this properly as the man page doesn't really say anything about it, and I can't find anything on the web either.

A quick hack on the source is probably faster 8)


Top
  
 
 Post subject: killing bt in a screen
PostPosted: Tue Feb 15, 2005 1:28 pm 
Hehe, your idea is really evil. Does this work ?

Code:
perl -e 'use Expect; $cmd = Expect->spawn("screen -dr"); $cmd->raw_pty(1); $cmd->send("q"); $cmd->expect(10,"\$");
$cmd->hard_close()'


Top
  
 
 Post subject: found a solution
PostPosted: Mon Feb 21, 2005 1:36 pm 
This should make bittornado save state on HUP and TERM signals.

Code:
--- /usr/bin/btlaunchmanycurses   2005-01-21 19:09:15.000000000 +0100
+++ /tmp/btlaunchmanycurses   2005-02-21 08:31:58.000000000 +0100
@@ -28,7 +28,7 @@
     import curses
     import curses.panel
     from curses.wrapper import wrapper as curses_wrapper
-    from signal import signal, SIGWINCH
+    from signal import signal, SIGWINCH, SIGTERM, SIGHUP
 except:
     print 'Textmode GUI initialization failed, cannot proceed.'
     print
@@ -92,9 +92,12 @@
         self.messages = []
         self.scroll_pos = 0
         self.scroll_time = 0
+        self.shutdown = False
         
         self.scrwin = scrwin
         signal(SIGWINCH, self.winch_handler)
+        signal(SIGTERM, self.term_handler)
+        signal(SIGHUP, self.term_handler)
         self.changeflag = Event()
         self._remake_window()
 
@@ -106,6 +109,9 @@
         self._remake_window()
         self._display_messages()
 
+    def term_handler(self,signum,stackframe):
+        self.shutdown = True
+
     def _remake_window(self):
         self.scrh, self.scrw = self.scrwin.getmaxyx()
         self.scrpan = curses.panel.new_panel(self.scrwin)
@@ -248,7 +254,7 @@
         curses.panel.update_panels()
         curses.doupdate()
 
-        return inchar in (ord('q'),ord('Q'))
+        return inchar in (ord('q'),ord('Q')) or self.shutdown
 
     def message(self, s):
         self.messages.append(strftime('%x %X - ',localtime(time()))+s)


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 7 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 145 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group