4 Written by BroytMann. Copyright (C) 2000-2007 PhiloSoft Design.
15 from subproc import Subprocess, RecordFile
17 # This is to catch 'close failed: [Errno 9] Bad file descriptor' message
18 # from os.close() in Subprocess.die() and errors from from the subprocess.
19 sys.stderr = open("err.log", 'a')
25 global check_subp, subp_pipe
27 if log: log(" restarting hanging subprocess")
31 def restart_subp(log):
32 global check_subp, subp_pipe
35 check_subp = Subprocess("%s/Robots/bkmk_rforking_sub.py" % os.path.dirname(sys.argv[0]),
37 subp_pipe = RecordFile(check_subp)
40 from bkmk_objects import Robot
42 class robot_forking(Robot):
43 def check_url(self, bookmark):
45 restart_subp(self.log) # Not restart, just start afresh
48 save_parent = bookmark.parent
49 bookmark.parent = None
51 bookmark.tempfname = self.tempfname
52 subp_pipe.write_record(pickle.dumps(bookmark))
54 if check_subp.waitForPendingChar(300): # wait 5 minutes
55 new_b = pickle.loads(subp_pipe.read_record())
56 for attr in ("error", "no_error",
57 "moved", "size", "md5", "real_title",
58 "last_tested", "last_modified", "test_time", "icon"):
59 if hasattr(new_b, attr):
60 setattr(bookmark, attr, getattr(new_b, attr))
62 bookmark.error = "Subprocess connection timed out"
63 restart_subp(self.log)
65 bookmark.parent = save_parent
68 error = check_subp.readPendingErrLine()
71 sys.stderr.write("(subp) " + error)
74 except KeyboardInterrupt:
82 stop_subp(None) # Stop subprocess; do not log restarting