2012-03-25T00:48:31 *** Chris_0076 has joined #aichallenge 2012-03-25T00:55:45 *** yoden has quit IRC (Quit: Leaving.) 2012-03-25T01:32:09 what does this mean? It is not guaranteed that __del__() methods are called for objects that still exist when the interpreter exits. 2012-03-25T01:32:21 nvm, wrong channel, lol 2012-03-25T01:33:18 it gets called when the object is GC'ed 2012-03-25T01:33:28 the interpreter is allowed to just be lazy and let the OS free the memory 2012-03-25T01:33:44 don't know what cpython actually does 2012-03-25T01:34:40 for sanity, you want to assume that __del__ is only called when you del the object itself 2012-03-25T01:35:02 cause otherwise you have no guarantee it'll be run in a reasonable timeframe. ie. ever. 2012-03-25T01:41:48 yeah, so the issue i was having 2012-03-25T01:41:56 is that i needed a global inside my del 2012-03-25T01:42:06 but by the time it got to del, it deleted that global 2012-03-25T01:42:12 so it was complaining that it couldn't find it 2012-03-25T01:42:26 kind of uncool 2012-03-25T01:42:34 i fixed it by making the global part of the class 2012-03-25T01:42:47 kinda sad that there isn't a better way 2012-03-25T01:43:25 usually not needing a __del__ function is good 2012-03-25T01:43:35 this is for a serial device thing 2012-03-25T01:43:42 i need to send a message just before app closes 2012-03-25T01:43:44 i haven't come across many circumstances where it's needed 2012-03-25T01:43:46 ah 2012-03-25T01:44:05 atexit? 2012-03-25T01:44:07 amstan: could you force the use of a with statement? 2012-03-25T01:44:12 didn't want to deal with atexit, i liked the __del__ thing more 2012-03-25T01:44:19 __enter__ and __exit__ 2012-03-25T01:44:20 :P 2012-03-25T01:44:22 thestinger: hmm? 2012-03-25T01:44:43 yeah, i'd recommend that, too 2012-03-25T01:44:51 amstan: implement a context handler 2012-03-25T01:44:57 i'm not sure what you guys mean 2012-03-25T01:45:03 if you're using python2.7 or feel like importing with_statement from __future__ 2012-03-25T01:45:05 for what though? it's a device, it should be a class 2012-03-25T01:45:12 2.7, yes 2012-03-25T01:45:24 in 2.7 you can use with statements 2012-03-25T01:45:33 like with open(filename, 'r') as f: 2012-03-25T01:45:36 yes, but how and why? 2012-03-25T01:45:40 f is open within the block 2012-03-25T01:45:46 and once you leave the block it's closed 2012-03-25T01:45:57 amstan: it's equivalent to RAII in C++ 2012-03-25T01:46:04 no matter how you leave the block 2012-03-25T01:46:05 it doesn't rely on the garbage collector doing the right thing 2012-03-25T01:46:06 what i did: i moved that finally block into the __del__ of the class Floppy: https://github.com/amstan/floppy/blob/master/interface/floppy.py#L145 2012-03-25T01:46:08 and it's exception safe 2012-03-25T01:46:36 try/finally can be replaced by a with statement 2012-03-25T01:46:36 the garbage collector is fairly exception friendly as well 2012-03-25T01:46:44 yes, but i'm not using that try finally 2012-03-25T01:46:53 i wanted to replace that 2012-03-25T01:48:16 yeah 2012-03-25T01:48:17 a with statement handles it inside the class 2012-03-25T01:48:33 it gives an interface that's easy to use, and the user of the interface doesn't have to worry or call del themselves 2012-03-25T01:49:08 you should be able to define __exit__ as what you have as del 2012-03-25T01:49:13 and __enter__ as simply pass 2012-03-25T01:49:25 or 2012-03-25T01:49:39 define a wrapper class whose __enter__ method creates a Floppy 2012-03-25T01:49:45 and whose __exit__ method dels it 2012-03-25T01:50:10 and then write "with ___:" 2012-03-25T01:50:12 Zannick: that's too complicated for what i wanted to do 2012-03-25T01:50:13 in place of try: 2012-03-25T01:50:35 my fix solved it, it's not too pretty but it's prettier than a wrapper class 2012-03-25T01:50:54 i'd go with the first one 2012-03-25T01:51:11 amstan: it's just as simple 2012-03-25T01:51:14 defining __enter__ and __exit__ on the class itself 2012-03-25T01:51:21 your __del__ is __exit__ _and_ close 2012-03-25T01:51:32 someone can either use with or do it explicitly/manually with .close 2012-03-25T01:52:08 with is pretty common to use for devices 2012-03-25T01:52:45 but that's just my 2c, that's how i'd do it 2012-03-25T01:52:52 glad to hear you got it working 2012-03-25T01:52:53 Zannick: https://github.com/amstan/floppy/commit/c0609bdc8f977c42e68d9d237fca29d25140700f 2012-03-25T01:53:49 oh! i can do __exit__ on Floppy you say and then use with Floppy() as floppy? that's a good idea 2012-03-25T01:54:00 yes. 2012-03-25T01:54:39 oh no, i have to indent everything one more level with that again 2012-03-25T01:54:45 haha 2012-03-25T01:55:01 amstan: that's why the implicit version in C++ is nice :P 2012-03-25T01:55:34 thestinger: you would think in python destructors would be easier 2012-03-25T01:55:40 but i guess nobody needs them too often 2012-03-25T01:55:45 garbage collection makes them pretty useless 2012-03-25T01:55:52 since it's not deterministic when it gets called 2012-03-25T01:56:20 in C++ you know exactly when they get called, and it will be the same with each run (even with smart pointers which is refcounting) 2012-03-25T01:56:41 D probably has the same thing (not sure) 2012-03-25T01:57:02 and I'm guessing Rust has something similar 2012-03-25T01:57:25 you also need __enter__ which can be simply "pass" (or move some of the logic from __init__ in) 2012-03-25T01:57:43 __enter__ doesn't really have to do anything 2012-03-25T01:57:49 Zannick: doesn't it have to return self? 2012-03-25T01:57:59 does it? 2012-03-25T01:58:21 hmm.. it's not as easy as just adding __exit__ 2012-03-25T01:58:36 Zannick: yeah, that's what with binds to the name you give it 2012-03-25T01:58:37 oh, indeed. 2012-03-25T01:59:25 i assumed "with foo as f" would call foo.__enter__() and save foo as f 2012-03-25T01:59:34 rather than as the return value of foo.__enter__() 2012-03-25T01:59:46 shows you what i know, only using with for files and locks ;) 2012-03-25T01:59:51 not sure why it does that, but there's probably a use case 2012-03-25T02:00:32 yeah, __enter__ must return self 2012-03-25T02:01:23 * Zannick is reading the PEP 2012-03-25T02:01:39 http://docs.python.org/reference/datamodel.html#context-managers there's the section on it 2012-03-25T02:01:48 http://docs.python.org/library/stdtypes.html#typecontextmanager more there 2012-03-25T02:02:00 idk still, it's rather ugly 2012-03-25T02:02:14 if i don't use a context switcher it won't stop the floppy properly 2012-03-25T02:02:27 amstan: do it like python's files 2012-03-25T02:02:53 but it's not really a file, it's an object 2012-03-25T02:03:02 yes.. i can't use context managers 2012-03-25T02:03:28 this class will be an attribute to another class 2012-03-25T02:03:53 and i have to init it in the init of the other class 2012-03-25T02:04:25 i won't be able to have it in a context switcher, unless i call the __enter__ and __exit__ manually, which defeat the point of having them in the first place 2012-03-25T02:05:06 oh, you can't edit the other class and it's the one dealing with the Floppy object? 2012-03-25T02:05:21 i can 2012-03-25T02:05:38 but the other class will have something like this in the init: self.floppy=Floppy(blabla) 2012-03-25T02:05:51 and then i'll use the floppy instance in the other methods as well 2012-03-25T02:06:22 I guess that forces you to give the other class __enter__ and __exit__ too 2012-03-25T02:06:34 that really complicates things 2012-03-25T02:06:36 and just call self.floppy.__exit__() in that exit 2012-03-25T02:06:44 yes, so that's just weird 2012-03-25T02:07:26 i would have recommended simply moving the stuff from __init__ into __enter__ and have withs all over your other class, but then you'd be constantly opening and closing the serial connection 2012-03-25T02:07:45 Zannick: I don't think you need a with in the other class 2012-03-25T02:07:50 you just make it a context handler too 2012-03-25T02:07:54 that's probably not a good idea 2012-03-25T02:08:11 because the serial driver for this uart device has problems as is 2012-03-25T02:08:14 i think i would still rather use atexit :P 2012-03-25T02:09:51 alternately 2012-03-25T02:10:14 make the other class the context manager, and have its __exit__ function do the cleanup on floppy 2012-03-25T02:10:29 you don't need to make Floppy a context manager in that case 2012-03-25T02:11:36 up to you 2012-03-25T02:12:05 and good luck 2012-03-25T02:12:11 * Zannick -> 2012-03-25T02:12:41 there's a possiblity i'll have more than 1 floppy for the other class 2012-03-25T02:14:14 amstan: http://sprunge.us/CQSG 2012-03-25T02:15:56 def __exit__(self, *args): 2012-03-25T02:16:04 for floppy in self.floppies: 2012-03-25T02:16:20 floppy.__exit__(*args) 2012-03-25T02:16:29 yes, but how is that better than what i already have? 2012-03-25T02:16:34 (or floppy.cleanup, etc. doesn't need to be called __exit__) 2012-03-25T02:17:03 code cleanliness? ;) 2012-03-25T02:17:05 * Zannick shrugs 2012-03-25T02:17:06 amstan: you know when it gets closed 2012-03-25T02:17:33 thestinger: but i don't care that much, if less than 1 second it's ok with me. 2012-03-25T02:18:04 __del__ is only run when it's garbage collected though 2012-03-25T02:18:13 it could be 10 mins, it might be never 2012-03-25T02:18:28 the main purpose of that code is to make the floppy shut up when i close the program 2012-03-25T02:18:42 so when i ctrl+c, i want that message sent before the program quits 2012-03-25T02:19:56 nice, gcc 4.7 2012-03-25T02:38:03 *** loglog has joined #aichallenge 2012-03-25T02:56:15 *** kurnevsky has joined #aichallenge 2012-03-25T03:23:25 *** thestinger has quit IRC (Quit: sleep) 2012-03-25T03:41:26 *** epicmonkey has joined #aichallenge 2012-03-25T03:46:31 *** loglog has quit IRC (Remote host closed the connection) 2012-03-25T03:46:48 *** loglog has joined #aichallenge 2012-03-25T03:47:09 *** Jak_o_Shadows has joined #aichallenge 2012-03-25T03:52:34 *** dici has joined #aichallenge 2012-03-25T04:48:39 *** loglog has quit IRC (Remote host closed the connection) 2012-03-25T05:01:11 *** dvladim has joined #aichallenge 2012-03-25T05:31:42 *** dvladim has quit IRC (Read error: Operation timed out) 2012-03-25T05:33:34 *** amstan has quit IRC (Ping timeout: 246 seconds) 2012-03-25T05:41:03 http://dis.4chan.org/read/prog/1331845575 2012-03-25T05:49:20 *** foRei has joined #aichallenge 2012-03-25T06:21:36 *** antimatroid has quit IRC (Ping timeout: 245 seconds) 2012-03-25T06:25:02 *** epicmonkey has quit IRC (Ping timeout: 246 seconds) 2012-03-25T06:36:01 *** antimatroid has joined #aichallenge 2012-03-25T06:37:40 *** epicmonkey has joined #aichallenge 2012-03-25T06:55:26 *** choas has joined #aichallenge 2012-03-25T07:03:23 *** Kingpin13 has quit IRC (Quit: quit) 2012-03-25T07:12:25 *** Kingpin13 has joined #aichallenge 2012-03-25T07:14:14 *** loglog has joined #aichallenge 2012-03-25T07:16:51 *** choas has quit IRC (Ping timeout: 265 seconds) 2012-03-25T07:38:24 *** coeus has quit IRC (Read error: Operation timed out) 2012-03-25T07:58:27 *** hara has joined #aichallenge 2012-03-25T07:58:27 *** mceier has joined #aichallenge 2012-03-25T08:13:25 *** dici has quit IRC (Read error: Connection reset by peer) 2012-03-25T08:21:47 *** loglog has quit IRC (Remote host closed the connection) 2012-03-25T08:22:03 *** loglog has joined #aichallenge 2012-03-25T08:24:39 *** Jak_o_Shadows has quit IRC (Remote host closed the connection) 2012-03-25T08:38:10 *** mleyen has joined #aichallenge 2012-03-25T08:48:30 *** archdori has joined #aichallenge 2012-03-25T09:07:58 *** cyphase has quit IRC (Read error: Connection reset by peer) 2012-03-25T09:10:33 *** archdori has quit IRC (Remote host closed the connection) 2012-03-25T09:17:21 *** dvladim has joined #aichallenge 2012-03-25T09:27:50 *** loglog has quit IRC (Remote host closed the connection) 2012-03-25T09:32:20 *** UncleVasya has joined #aichallenge 2012-03-25T09:59:24 *** loglog has joined #aichallenge 2012-03-25T10:03:35 *** thestinger has joined #aichallenge 2012-03-25T10:17:02 *** UncleVasya has quit IRC (Ping timeout: 260 seconds) 2012-03-25T10:27:02 *** yoden has joined #aichallenge 2012-03-25T10:32:31 *** KP13 has joined #aichallenge 2012-03-25T10:33:37 *** Kingpin13 has quit IRC (Ping timeout: 244 seconds) 2012-03-25T10:37:52 *** Kingpin13 has joined #aichallenge 2012-03-25T10:37:52 *** Kingpin13 has joined #aichallenge 2012-03-25T10:39:09 *** KP13 has quit IRC (Ping timeout: 246 seconds) 2012-03-25T10:39:58 *** sigh has quit IRC (Remote host closed the connection) 2012-03-25T10:40:53 *** Kingpin13 has quit IRC (Max SendQ exceeded) 2012-03-25T10:41:59 *** Kingpin13 has joined #aichallenge 2012-03-25T10:53:27 *** Kingpin13 has quit IRC (Ping timeout: 260 seconds) 2012-03-25T10:53:37 *** KP13 has joined #aichallenge 2012-03-25T11:03:23 *** hara has quit IRC () 2012-03-25T11:07:35 *** loglog has quit IRC (Remote host closed the connection) 2012-03-25T11:14:25 *** dvladim has quit IRC (Ping timeout: 264 seconds) 2012-03-25T11:24:10 *** KP13 is now known as Kingpin13 2012-03-25T11:38:40 *** amstan has joined #aichallenge 2012-03-25T11:38:40 *** ChanServ sets mode: +o amstan 2012-03-25T12:05:10 *** coeus has joined #aichallenge 2012-03-25T12:20:18 *** coeus has quit IRC (Ping timeout: 246 seconds) 2012-03-25T12:24:59 *** epicmonkey_ has joined #aichallenge 2012-03-25T12:25:03 *** epicmonkey has quit IRC (Read error: No route to host) 2012-03-25T13:01:18 *** loglog has joined #aichallenge 2012-03-25T13:08:22 *** mleyen has quit IRC (Quit: ~ Trillian Astra - www.trillian.im ~) 2012-03-25T13:08:25 *** dici has joined #aichallenge 2012-03-25T13:10:19 *** hara has joined #aichallenge 2012-03-25T14:04:26 *** loglog has quit IRC (Remote host closed the connection) 2012-03-25T14:04:39 *** cyphase has joined #aichallenge 2012-03-25T14:04:44 *** loglog has joined #aichallenge 2012-03-25T14:07:35 *** Palmik has joined #aichallenge 2012-03-25T20:19:48 *** contestbot has joined #aichallenge 2012-03-25T20:19:48 *** ChanServ sets mode: +o contestbot 2012-03-25T20:37:35 *** epicmonkey_ has joined #aichallenge 2012-03-25T20:49:53 *** epicmonkey_ has quit IRC (Ping timeout: 246 seconds) 2012-03-25T21:05:27 *** archdori_ has joined #aichallenge 2012-03-25T21:08:53 *** archdori has quit IRC (Ping timeout: 260 seconds) 2012-03-25T21:32:13 *** coeus has joined #aichallenge 2012-03-25T21:33:48 *** archdori_ has quit IRC (Ping timeout: 245 seconds) 2012-03-25T21:34:08 *** archdori has joined #aichallenge 2012-03-25T22:04:32 *** dom7b5 has joined #aichallenge 2012-03-25T22:58:10 *** dom7b5 has quit IRC () 2012-03-25T23:17:54 *** Bluedgis has quit IRC (Ping timeout: 272 seconds) 2012-03-25T23:17:59 *** Bluedgis has joined #aichallenge