--- Log opened Tue May 25 00:00:11 2010 |
00:50 | | shade_of_cpux is now known as cpux |
01:18 | | gnolam [lenin@Nightstar-38637aa0.priv.bahnhof.se] has quit [[NS] Quit: Z?] |
02:01 | | Searh [Z@26ECB6.A4B64C.298B52.D80DA0] has quit [Ping timeout: 121 seconds] |
02:11 | | Searh [Z@26ECB6.A4B64C.298B52.D80DA0] has joined #code |
02:20 | | SmithKurosaki [Smith@Nightstar-26933809.dsl.teksavvy.com] has joined #code |
03:43 | | Searh [Z@26ECB6.A4B64C.298B52.D80DA0] has quit [Ping timeout: 121 seconds] |
03:48 | | Thaqui [Thaqui@27B34E.D54D49.F53FA1.6A113C] has quit [Connection closed] |
04:19 | | Searh [Z@3A600C.A966FF.5BF32D.8E7ABA] has joined #code |
05:06 | | Thaqui [Thaqui@27B34E.D54D49.F53FA1.6A113C] has joined #code |
05:13 | | celticminstrel [celticminstre@Nightstar-f8b608eb.cable.rogers.com] has quit [[NS] Quit: *hums* Can't stay now!] |
05:42 | | Derakon [Derakon@Nightstar-5213d778.ca.comcast.net] has quit [Client closed the connection] |
05:51 | | Derakon [Derakon@Nightstar-5213d778.ca.comcast.net] has joined #code |
05:51 | | mode/#code [+o Derakon] by Reiver |
06:08 | | Searh [Z@3A600C.A966FF.5BF32D.8E7ABA] has quit [Ping timeout: 121 seconds] |
06:15 | | Orth [orthianz@Nightstar-9f26e241.xnet.co.nz] has quit [Connection reset by peer] |
06:20 | | Reiv[Graduate] [orthianz@Nightstar-9f26e241.xnet.co.nz] has joined #code |
06:21 | | Reiv[Graduate] [orthianz@Nightstar-9f26e241.xnet.co.nz] has quit [Client closed the connection] |
06:28 | | Derakon is now known as Derakon[AFK] |
06:29 | | Reiv[Graduate] [orthianz@Nightstar-9f26e241.xnet.co.nz] has joined #code |
06:38 | | AnnoDomini [annodomini@Nightstar-826e1954.adsl.tpnet.pl] has joined #code |
06:38 | | mode/#code [+o AnnoDomini] by Reiver |
08:17 | | OperatorAbu_ [ad@Nightstar-cbc38333.gprs.plus.pl] has joined #code |
08:17 | < OperatorAbu_> | I cannot brain. I have the dumb. |
08:17 | < Tarinaky> | Know the feeling. |
08:18 | < OperatorAbu_> | I have the angle, the radius and the center point coordinates. I need to determine the coordinates of the point on the circle of the radius surrounding the center point where the angle would point. |
08:19 | < OperatorAbu_> | So I can drawLine() and get a line from the center to the circle. |
08:19 | < OperatorAbu_> | How do I determine the coordinates? |
08:20 | < Tarinaky> | tan theta = y/x |
08:20 | < Tarinaky> | x^2 + y^2 = R^2 |
08:20 | < Tarinaky> | Solve for x. |
08:20 | < Tarinaky> | Solve for y. |
08:21 | < OperatorAbu_> | That doesn't help me. I said I cannot brain. |
08:23 | < Tarinaky> | There're a lot of different ways of doing it tbh :/ |
08:24 | <@Vornicus> | c.x + r * sin(a) |
08:24 | <@Vornicus> | c.y + r * cos(a) |
08:24 | <@Vornicus> | er, other way around. x is cos, y is sin |
08:25 | < OperatorAbu_> | That helps. Thanks. |
08:50 | < OperatorAbu_> | Okay. My analog clock project actually looks non-shitty now. |
08:52 | | You're now known as TheWatcher |
08:56 | | OperatorAbu_ [ad@Nightstar-cbc38333.gprs.plus.pl] has quit [Client exited] |
10:32 | | gnolam [lenin@Nightstar-38637aa0.priv.bahnhof.se] has joined #code |
10:43 | | Thaqui [Thaqui@27B34E.D54D49.F53FA1.6A113C] has quit [Connection closed] |
11:04 | | Tarinaky [Tarinaky@Nightstar-3a7168a8.adsl.virginmedia.net] has quit [Operation timed out] |
11:19 | | Tarinaky [Tarinaky@Nightstar-bb12c626.adsl.virginmedia.net] has joined #code |
11:40 | | Vornicus is now known as Vornicus-Latens |
11:42 | | Searh [Z@3A600C.A966FF.5BF32D.8E7ABA] has joined #code |
12:15 | | * gnolam ponders moon phases. |
12:28 | | Searh [Z@3A600C.A966FF.5BF32D.8E7ABA] has quit [Ping timeout: 121 seconds] |
12:34 | | Orth [orthianz@Nightstar-a016c490.xnet.co.nz] has joined #code |
12:37 | | Reiv[Graduate] [orthianz@Nightstar-9f26e241.xnet.co.nz] has quit [Ping timeout: 121 seconds] |
12:59 | | Searh [Z@26ECB6.A4B64C.298B52.D80DA0] has joined #code |
13:40 | | ToxicFrog [ToxicFrog@ServerAdministrator.Nightstar.Net] has quit [Connection reset by peer] |
13:48 | | celticminstrel [celticminstre@Nightstar-f8b608eb.cable.rogers.com] has joined #code |
14:15 | | Searh [Z@26ECB6.A4B64C.298B52.D80DA0] has quit [Ping timeout: 121 seconds] |
14:19 | | Serah [Z@26ECB6.A4B64C.298B52.D80DA0] has joined #code |
14:30 | | ToxicFrog [ToxicFrog@ServerAdministrator.Nightstar.Net] has joined #code |
14:30 | | mode/#code [+o ToxicFrog] by Reiver |
15:32 | | Orth [orthianz@Nightstar-a016c490.xnet.co.nz] has quit [Client closed the connection] |
15:33 | | Reiv[Graduate] [orthianz@Nightstar-a016c490.xnet.co.nz] has joined #code |
15:34 | | Orth [orthianz@Nightstar-deea5416.xnet.co.nz] has joined #code |
15:37 | | Reiv[Graduate] [orthianz@Nightstar-a016c490.xnet.co.nz] has quit [Ping timeout: 121 seconds] |
15:56 | | Serah [Z@26ECB6.A4B64C.298B52.D80DA0] has quit [Ping timeout: 121 seconds] |
16:07 | | Serah [Z@26ECB6.A4B64C.298B52.D80DA0] has joined #code |
17:38 | | Attilla [Attilla@Nightstar-5b561d6f.threembb.co.uk] has joined #code |
17:38 | | mode/#code [+o Attilla] by Reiver |
19:08 | | Vornicus-Latens is now known as Vornicus |
19:11 | <@AnnoDomini> | http://i48.tinypic.com/2anfgh.jpg <- Stealing images from Windows always works. :D |
21:00 | | AbuDhabi [annodomini@Nightstar-8dd6c2ef.adsl.tpnet.pl] has joined #code |
21:03 | | AnnoDomini [annodomini@Nightstar-826e1954.adsl.tpnet.pl] has quit [Ping timeout: 121 seconds] |
21:11 | | Derakon [Derakon@Nightstar-1ffd02e6.ucsf.edu] has joined #code |
21:11 | | mode/#code [+o Derakon] by Reiver |
21:11 | | * Derakon sighs. |
21:12 | <@Derakon> | grep -r "X\." * | grep -v html | perl -ne 'chomp; /X\.(\w+)/; print "$1\n"'|sort -u | wc -l |
21:12 | <@Derakon> | 126 |
21:12 | <@Derakon> | Keep in mind that the "X" module contains no functions. |
21:12 | < celticminstrel> | ...what does it contain, then? |
21:12 | <@Derakon> | These are all variables that some other module has decided to stuff into the "X" module. I.e. they are global variables. |
21:12 | < celticminstrel> | Ah. |
21:12 | <@Derakon> | There's actual code in the module, which runs when it is imported. It of course has nothing to do with any of these variables. |
21:13 | <@Derakon> | (There were 130 earlier this morning, but I deleted two and moved two others to only be in scope in the module they're actually used in) |
21:23 | | Thaqui [Thaqui@27B34E.D54D49.F53FA1.6A113C] has joined #code |
21:23 | < celticminstrel> | Anyone know what result codes Python returns? |
21:24 | <@Derakon> | Context? |
21:25 | < celticminstrel> | Well, I want to write a shell script that will call my Python script over and over until the Python script exits with a custom result code. |
21:25 | <@jerith> | celticminstrel: "sys.exit(whatever)" |
21:25 | < celticminstrel> | Yes, I know that part. I just want to make sure I don't exit with a result code that Python might use normally, for example upon an uncaught exception. |
21:26 | <@jerith> | mentar:~ jerith$ python -c 'print 1/0'; echo $? |
21:26 | <@jerith> | Traceback (most recent call last): File "<string>", line 1, in <module> |
21:26 | <@jerith> | ZeroDivisionError: integer division or modulo by zero |
21:26 | <@jerith> | 1 |
21:27 | <@jerith> | Every exception I've tried returns 1. |
21:27 | <@ToxicFrog> | I suspect it just uses EXIT_SUCCESS and EXIT_FAILURE, which macro to 0 and 1 in most places. |
21:27 | <@jerith> | Including SyntaxError. |
21:27 | < celticminstrel> | Okay, I'll just select a random 4-digit number then. |
21:28 | <@Derakon> | Man, "echo $?" is a lot easier than what I was trying. |
21:28 | <@Derakon> | Which involved doing perl -e 'print `python -c...`' |
21:28 | <@Derakon> | ?.? |
21:28 | < celticminstrel> | ... |
21:29 | | * jerith grins. |
21:32 | < celticminstrel> | Now I need to write the shell script. |
21:34 | < celticminstrel> | '2>>crash.log' to redirect errors? |
21:34 | <@jerith> | That redirects stderr. |
21:35 | < celticminstrel> | Surely Python prints its errors to stderr? |
21:35 | <@ToxicFrog> | Yes. |
21:35 | < celticminstrel> | Well then. |
21:36 | <@ToxicFrog> | Just pointing out that "redirect stderr" is not necessarily the same thing as "redirecting errors"; not all programs put errors on stderr, and getting non-error things on stderr is also common. |
21:36 | < celticminstrel> | I see. |
21:36 | <@jerith> | In particular, a lot of utils detect whether they're connected to a terminal or not and send some stuff to stderr if they aren't. |
21:37 | <@jerith> | curl, for example. |
21:39 | < celticminstrel> | result=0; while [ $result != 9273 ]; do ircbot.py >/dev/null 2>>crash.log; result=$?; done; |
21:41 | <@Derakon> | What is your goal here? To auto-reconnect the bot when it's disconnected? |
21:41 | <@Derakon> | Or when it crashes? |
21:41 | < celticminstrel> | When it crashes, or when I tell it to restart (as opposed to telling it to quit). |
21:42 | <@ToxicFrog> | Why not have it restart itself? |
21:42 | <@Derakon> | It seems to me that you should be encapsulating the bot logic in some wrapper code that a) handles restarting, and b) uses a try/catch block. |
21:42 | <@Derakon> | Then you don't need to bother with wrapping the entire program in a shell script. |
21:42 | < celticminstrel> | ToxicFrog: How? |
21:43 | <@Derakon> | http://paste.ubuntu.com/439534/ |
21:44 | <@Derakon> | Any exceptions raised by runBot that aren't RestartException (which is a fictional exception that you could easily make yourself) cause the program to halt; otherwise the bot restarts. |
21:44 | <@Derakon> | You could easily change that to "restart on all exceptions except StopException" if you wanted to. |
21:44 | <@ToxicFrog> | celticminstrel: the right way: do it as Derakon says. |
21:45 | <@ToxicFrog> | The other way: on restart, use os.exec() (or whatever python calls it). |
21:45 | < Tarinaky> | You know your project is in trouble when you're not even 1 day into it and the other guy flakes out and disappears off the internet. |
21:45 | < Tarinaky> | :/ |
21:45 | <@Derakon> | TF: ;_; |
21:45 | <@Derakon> | (Also, it's just "exec"; it's a language keyword) |
21:47 | | * celticminstrel headshakes. |
21:47 | < celticminstrel> | That's for executing Python code. |
21:48 | <@ToxicFrog> | Derakon: I'm talking about exec as in fork-exec, not as in eval |
21:48 | <@Derakon> | Oh. |
21:48 | <@Derakon> | Then you want the subprocess module. |
21:48 | <@ToxicFrog> | ...subprocess exec ow my brain |
21:49 | <@Derakon> | Oh, wait, no, my bad. |
21:49 | <@Vornicus> | exec is Deep Magic |
21:49 | < celticminstrel> | Yeah, subprocess. I use "import subprocess as fork" because it's shorter. |
21:49 | < celticminstrel> | And subprocess has an implicit fork anyway. |
21:49 | <@Derakon> | ...subprocess can fork? I thought it was just for commandline stuff. |
21:49 | < celticminstrel> | No, it's for forking. |
21:50 | <@Derakon> | Still, the right way to do this is to wrap the entire program in a loop that restarts it as needed. |
21:50 | <@Derakon> | Not to wrap the program in another program. |
21:50 | < celticminstrel> | Okay, so I need a command to write the exception to a file. |
21:50 | < gnolam> | Tarinaky: what kind of a project? |
21:50 | < celticminstrel> | I think I did that somewhere. |
21:50 | < celticminstrel> | Derakon, what does the "pass" in the except clause do? |
21:51 | < Namegduf> | Python? |
21:51 | <@Derakon> | Celticminstrel: cause the exception to be ignored. |
21:51 | < Namegduf> | "pass" is a no-op statement used where a statement is equired and you don't want to do anything |
21:51 | <@Derakon> | All other exceptions in that example will cause the loop to halt. |
21:51 | < Namegduf> | Often used to stub out code and never ever used in place of proper exception handling |
21:51 | < celticminstrel> | Ah. So, it's the Python equivalent of a lone semicolon? |
21:51 | < Tarinaky> | gnolam: The game we were going to make over the summer. :/ |
21:51 | < Tarinaky> | gnolam: I needed his help with the AI because I have no idea how to do it. |
21:51 | <@Derakon> | It's the Python way of saying "The language requires me to put an indentation level here, but I don't actually want to do anything" |
21:51 | < Namegduf> | (In reality, it's often used where the proper thing is "do nothing") |
21:52 | < celticminstrel> | I've always used None in that situation. |
21:52 | < Namegduf> | A a statement? |
21:52 | <@Derakon> | Use pass instead. |
21:52 | < Namegduf> | "pass" is the right way, yeah. |
21:53 | | * Derakon is reminded of an email he once sent to one of his profs, asking if he should use "continue" in one of his loops, or else an if/else statement that would accomplish the same thing. The response was "Yes, you should use the built-in language features that accomplish what you are trying to do." |
21:53 | <@Derakon> | (I recognize in this case that you didn't actually know about "pass" yet) |
21:53 | < Namegduf> | Well, it's a legitimate question in that continue is not Structured Programming in some cases |
21:53 | <@ToxicFrog> | Derakon: spawning seperate programs is forking. What kind of hurts me is that if you want to just exec, you go to subprocess anyways. |
21:54 | <@ToxicFrog> | Although I guess is makes sense given that spawn == fork+exec |
21:54 | <@Derakon> | TF: I mentally pigeonhole fork into "start a child process that is identical to the parent process except in the retutrn result of fork()" |
21:54 | <@Derakon> | Er, return. |
21:55 | <@ToxicFrog> | Yes. But it's also the first half of "start a child process doing something else", and all of the "run this shell command" style calls are implemented in terms of it. |
21:55 | <@Derakon> | Roger. |
21:55 | < celticminstrel> | ...wait. I would need to catch all exceptions, not just StopException. |
21:56 | <@Derakon> | You can have multiple except statements. |
21:57 | <@Derakon> | http://paste.ubuntu.com/439538/ |
21:57 | <@jerith> | You catch StopException and sys.exit() in that block. Then you catch everything else, log it and bounce back to the top of the loop. |
21:57 | <@Derakon> | Jynx. :p |
21:57 | < celticminstrel> | Yeah. Is "except Exception as x' sufficient, or is there a possibility of exceptions that aren't caught by that? |
21:58 | <@jerith> | celticminstrel: That's py3k syntax. |
21:58 | <@Derakon> | All exceptions inherit from Exception. |
21:58 | < celticminstrel> | Jerith: It's valid in 2.6 as well. |
21:58 | <@ToxicFrog> | Can you throw non-exceptions in python? |
21:59 | <@Derakon> | "The argument to raise is an exception class or instance to be raised." |
21:59 | < celticminstrel> | You used to be able to throw strings, but no longer, I think. |
21:59 | <@Derakon> | From http://docs.python.org/tutorial/errors.html#raising-exceptions |
21:59 | <@jerith> | I generally just "except:" and then use sys.exc_info() or whatever it is. |
21:59 | <@Derakon> | And yeah, raising strings as exceptions is deprecated. |
21:59 | < Namegduf> | Wouldn't they turn into Exception("String")? |
21:59 | <@jerith> | Since if I'm doing that it's nice to have the stack trace as well. |
22:00 | < celticminstrel> | I'm pretty sure the stack trace is an attribute of the exception/ |
22:00 | <@Derakon> | Namegduf: yep. |
22:00 | <@jerith> | celticminstrel: It isn't. |
22:00 | <@Derakon> | The stack trace is generally accessed through the traceback module. |
22:00 | <@jerith> | It's very expensive to keep around, because you have to save all the stack frames. |
22:00 | <@Derakon> | I'd surmise that exc_info just does that for you behind the scenes. |
22:01 | <@jerith> | Derakon: The traceback module came later, and it's basically tools that make dealing with it easier. |
22:01 | < gnolam> | Tarinaky: Pfft, then it's expected. :) |
22:01 | <@Derakon> | Jerith: ah? I still suspect that the Python devs make use of it behind the scenes now. :) |
22:02 | <@jerith> | Derakon: No, the traceback module calls sys.exc_info(). |
22:03 | <@jerith> | traceback.print_exc([limit[, file]])? This is a shorthand for print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback, limit, file). (In fact, it uses sys.exc_info() to retrieve the same information in a thread-safe way instead of using the deprecated variables.) |
22:03 | < Tarinaky> | gnolam: How so? |
22:03 | < Tarinaky> | gnolam: I've known the guy since I was 10 :/ |
22:04 | <@Derakon> | Oh, well. |
22:04 | < gnolam> | Ah. |
22:04 | <@jerith> | There are dire warnings about assigning the traceback object to a variable, because it has cycles in it and stuff. |
22:04 | < celticminstrel> | So 'class StopException(Exception): pass'? |
22:05 | <@jerith> | celticminstrel: That works. |
22:05 | < gnolam> | Still. Non-clue-by-four-distance game projects usually fall apart quickly. |
22:12 | < celticminstrel> | ...logging exception to file. |
22:12 | | * celticminstrel goes to look up the place I did that before. |
22:12 | <@Derakon> | You want the logging module. |
22:12 | < Tarinaky> | gnolam: True. |
22:12 | < Tarinaky> | gnolam: I expected the problem would be lesser since it was just two programmers :x |
22:13 | < celticminstrel> | ...I do? |
22:13 | | * celticminstrel wanders off to look that up. |
22:13 | <@Derakon> | IMO any reasonably complicated program should be using a logger. |
22:14 | <@Derakon> | If for no other reason than to be able to suppress debug-level output when you don't want to see it. |
22:14 | < celticminstrel> | Huh. ThunderBird just randomly crashed. |
22:15 | < celticminstrel> | This program sends debug-level output to stdout, because that's what the library does. I could suppress it by overriding the debug function, I guess. |
22:20 | <@jerith> | ... what library is this? |
22:20 | < celticminstrel> | An IRC library I found in pypi. |
22:20 | | RichardBarrell [mycatverbs@Nightstar-58acb782.cable.virginmedia.com] has joined #code |
22:20 | <@jerith> | No library should *ever* write to stdout unless that is its specific purpose. |
22:21 | < celticminstrel> | All its debugging is sent to the debug_print method, which prints to stdout. |
22:21 | <@jerith> | The only Python IRC library I've seen that's worth using is teh one in Twisted. :-) |
22:21 | < celticminstrel> | And by "debugging", I mean "every raw IRC command". |
22:21 | <@jerith> | Kill it with fire. |
22:21 | < celticminstrel> | Meh. It works. |
22:21 | <@jerith> | Seriously. |
22:22 | < celticminstrel> | And methods can me overridden, right? |
22:22 | < Namegduf> | If it sucks that much, I'd just write my own IRC parsing. |
22:22 | < celticminstrel> | Namegduf: Using this library means I don't need to learn about sockets. :P |
22:22 | <@jerith> | If they're doing stuff like that, they're almost certainly crap in other ways too. |
22:22 | <@Derakon> | Celticminstrel: if you modify a library by manually changing what its function definitions are at runtime, you're no better than Sebastian. |
22:22 | < celticminstrel> | ...the library defines a class which you extend. |
22:22 | <@jerith> | Derakon: I've monkey-patched libraries, but only as a last resort. |
22:23 | <@Derakon> | Ah, that's different. |
22:23 | <@Derakon> | Jerith: yeah, I meant more along the lines of "import irclib; irclib.debug_print = lambda a: a_ |
22:23 | <@jerith> | Ah, it is different. Still, it's The Wrong Thing. |
22:23 | <@Derakon> | s/_/"/ |
22:24 | <@jerith> | Derakon: I've done stuff pretty similar to that, actually. |
22:24 | <@jerith> | Well, I redefined a couple of functions that had broken assumptions baked in. |
22:24 | <@Derakon> | ;_; |
22:26 | | * celticminstrel pokes at the logging module. |
22:30 | <@Derakon> | (I actually ended up writing my own logging module, just because I didn't know about Python's at the time I started Jetblade. They're very easy to make, really, especially if you don't need any fancy formatting stuff) |
22:31 | <@Derakon> | Jetblade's logger: https://jetblade.googlecode.com/hg/logger.py |
22:31 | <@jerith> | Python's logging module is relatively new, as defined by "added since I started messing about with Python". |
22:31 | < celticminstrel> | Reinventing the wheel may be frowned upon, but sometimes it's fun! |
22:31 | <@Derakon> | Heh. |
22:32 | < celticminstrel> | Ooh! logging.exception()! |
22:32 | < celticminstrel> | Looks like just what I need. |
22:33 | < celticminstrel> | Is the logger unbuffered? |
22:34 | < celticminstrel> | I suspect not... |
22:34 | <@jerith> | celticminstrel: It depends on the handler. |
22:35 | < celticminstrel> | ...oh. |
22:51 | < Tarinaky> | What's a logger? :x |
22:51 | <@McMartin> | Library that keeps a log |
22:53 | <@Derakon> | It's basically an advanced version of using print statements to track what your program is doing. |
22:54 | <@Derakon> | Typically loggers let you set a priority on each message that they log (debug, inform, warn, error, fatal) and let you set the log level -- messages with insufficient priorities are dropped on the floor. |
22:54 | <@Derakon> | So if your log level is set to inform, then you can have 'log.debug("In the Foo constructor")' in your code without actually generating any output. |
22:54 | <@McMartin> | And you can change it dynamically, which means in practice that you can ship with the print statements in. |
22:54 | < Tarinaky> | Ahhh. |
22:54 | <@Derakon> | Though there's still some cost to evaluating the logger code. |
22:55 | <@Derakon> | I had a project back in college that involved printing out massive arrays of numbers, and we couldn't leave the logging code in because even though the lines didn't get printed, they still got evaluated. |
22:55 | <@jerith> | You can also change it per-logger. Typically, there's a logger per module or something. |
22:55 | <@jerith> | And it's hierarchical. |
22:55 | | * Derakon eliminates four more global variables from the microscope code. \o/ |
22:55 | <@jerith> | So I can have my code under test logging at DEBUG and everything else logging at INFO. |
22:56 | <@jerith> | Derakon: Most logging systems let you inspect the log level. |
22:56 | <@Derakon> | Jerith: oh, yeah, actually that's what we ended up doing. |
22:57 | <@Derakon> | My mistake. |
22:57 | <@jerith> | So you can say "if log.level_debug(): log.debug(expensive_thing())" or whatever. |
22:57 | <@Derakon> | Which is pretty clunky, mind. |
22:58 | < Namegduf> | First-class functions could help in some cases, but as a general construct might just get MORE clunky. |
22:58 | <@Derakon> | Loggers also often include formatting capabilities to include timestamps and make your logs prettier and so on. |
23:01 | < RichardBarrell> | syslog! |
23:01 | <@Derakon> | Sysloq isn't here right now... |
23:02 | < Namegduf> | import sysloq |
23:02 | <@McMartin> | Isn't that one to many s's? |
23:02 | <@jerith> | Syloq. |
23:02 | <@Derakon> | Oh yeah, that's his name. |
23:03 | < RichardBarrell> | from syslog import syslog, LOG_ERR, openlog; openlog("myprogram", 0); syslog(LOG_ERR, "damn! damn! damn!") |
23:04 | <@Derakon> | Hee. |
23:05 | <@jerith> | Or just use the logging module's syslog handler. |
23:18 | < celticminstrel> | ...that loop is sufficient to auto-restart after a crash, but it won't work for auto-restarting due to code changes. |
23:18 | <@Derakon> | Look into the reload() function. |
23:25 | | AbuDhabi [annodomini@Nightstar-8dd6c2ef.adsl.tpnet.pl] has quit [[NS] Quit: Sleeping.] |
23:26 | < celticminstrel> | I don't know how this file is being closed before I write to it, but I can check <file>.closed! |
23:26 | < RichardBarrell> | For programming languages that aren't dynamic, calling something like execvp(argv[0],argv); is another route. |
23:27 | <@jerith> | reload() isn't always very clean. |
23:29 | < celticminstrel> | ...so, reload(__main__)? |
23:29 | < RichardBarrell> | reload() doesn't do anything to help you with objects that were created before you called reload(). |
23:29 | < celticminstrel> | Sounds dubious though... |
23:30 | <@Derakon> | What reload() does is basically like re-importing a module. However, existing objects, and existing methods on those objects, are not updated. |
23:30 | < celticminstrel> | So, it's not equivalent to a sort of execvp(self) construction. |
23:31 | < RichardBarrell> | If you want to actually restart a script from scratch completely, I would recommend import os, sys; os.execvp(argv[0],argv); |
23:31 | < RichardBarrell> | No, reload() isn't anything like exec*()ing yourself again. |
23:32 | < RichardBarrell> | reload() reloads a single Python module that has already been imported earlier. Trying to use it to update code at runtime is generally fraught with peril. |
23:32 | <@jerith> | Quite. |
23:33 | <@Derakon> | It can work. I use it routinely. But yeah, you need to know how it works and how it doesn't work. |
23:34 | < celticminstrel> | execvp takes #! into account, right? |
23:34 | < RichardBarrell> | Yes. |
23:35 | < RichardBarrell> | Well, Unix does that for you, but yes. Provided that the script file has been "chmod +x"'d appropriately. |
23:57 | | Orth [orthianz@Nightstar-deea5416.xnet.co.nz] has quit [Client closed the connection] |
--- Log closed Wed May 26 00:00:12 2010 |