4 Written by Broytman. Copyright (C) 2000-2010 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
50 subp_pipe.write_record(pickle.dumps(bookmark))
52 if check_subp.waitForPendingChar(60): # wait a minute
53 new_b = pickle.loads(subp_pipe.read_record())
54 for attr in ("error", "no_error",
55 "moved", "size", "md5", "real_title",
56 "last_tested", "last_modified", "test_time",
58 if hasattr(new_b, attr):
59 setattr(bookmark, attr, getattr(new_b, attr))
61 bookmark.error = "Subprocess connection timed out"
62 restart_subp(self.log)
64 bookmark.parent = save_parent
67 error = check_subp.readPendingErrLine()
70 sys.stderr.write("(subp) " + error)
73 except KeyboardInterrupt:
81 stop_subp(None) # Stop subprocess; do not log restarting