| |
| |
| |
|
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Comments:
<0> i really thought it was the client because it worked before i switched to the whole gobject thing <0> but it's the server that's blocking <0> it's weird if i run the client it'll get the first response <0> and then if i hit ^c on the server <0> the other two responses will show up <1> drax: I didnt much like the built in async socket stuff, and twisted was too awkward <0> and when i do ^c <0> i get this traceback: <0> File "/usr/local/lib/python2.4/socket.py", line 303, in read <0> data = self._sock.recv(recv_size) <0> error: (4, 'Interrupted system call') <0> File "./rchat.py", line 60, in handle <0> dataIn = cPickle.load(self.rfile) <0> that's more pertinent <0> so it's blocking on the cPickle.load() <0> and i don't know why.
<0> i ***ume there is no EOF <0> but i don't know why there is no eof <2> what is self.rfile <0> graham_: the fd for the socket <1> oh... is that safe? <0> PKor: probably not :) <2> DraX: is that created by you or the SocketServer <0> SocketServer <1> could you shuttle the data into a buffer then load that instead? <1> I bet cPickle can't handle the chunking that goes on in the network layer <0> pkor: anytime i try to do a read operatoin of any kind it blocks. <2> DraX: you should be able to just get the raw socket and do a cPickle.loads() <1> graham is right if you dont mind blocking until the pickle data is all complete <0> graham_: the raw socket is self.connection <2> you should be able to read until it ends with a '.' which all pickles do, then just do a cPickle.loads() <3> graham_: __builtins__ = {} still isn't very safe <2> joedj: Why not? <1> drax: maybe the client isnt sending it all? check with tcpdump or ethereal? <3> graham_: you can access lotsa stuff through object.__subcl***es__() <2> PKor: good point <2> joedj: mostly i'm just looking to prevent importing and file access <2> joedj: and being able to "sys.exit(0)". <0> grr <0> it's binary data <0> so i can't really tell if it's complete <2> DraX: wait why is it binary? <3> >>> exec 'print (1).__cl***__.__bases__[0].__subcl***es__()[-1]' in {'__builtins__' : {}} <3> <cl*** 'subprocess.Popen'> <2> DraX: you dont need to wrap your sockets as files, you can use cPickle.dumps() to get a text rpr of the pickle then .send it <0> graham_: would that be better though? <2> DraX: well you dont need to have then as files, it adds a level of complexity that isn't needed. <2> DraX: i think it would be simpler, not sure about better, but it would be easier to see what is going on, then once you have everything working you could move toward making it a bit more complex. <2> DraX: but thats just my 2 cents <2> joedj: wow nice one <3> exec 'print (1).__cl***__.__bases__[0].__subcl***es__()[-1]("kill $PPID", shell=1)' in {'__builtins__' : {}} <3> heheh <0> graham_: still blocks if i use send and recv <4> joedj, that can only happen if you have imported subprocess, though <3> yeah <2> DraX: then i think i'll have to agree with PKor on this one, i think you are not connected or something. <0> graham_: the commands are sent, the daemon receives them <0> and if i hit ^c the client gets responses back <2> but the pickling isn't working <2> DraX: or its just blocking, waiting <0> it's blocking on the read <0> which to me sounds like no EOF <0> so it's "reading" for an eof and not getting one <2> well you dont want to send EOF to a socket <2> it will only block if there is no data to read <2> DraX: how do you know when your done reading all the data? <0> graham_: what do you mean? <2> DraX: well you send data from one place to another where you recv it right? <0> yes <2> DraX: how do you break up these messages, newline? <0> graham_: i'm just dumping the pickled data to the socket basically <0> which is probably the problem <2> is SocketServer supposed to be asynchronous ? <0> no <2> DraX: so you are in a loop that calls recv? <0> yes
<1> ttyl <2> DraX: ok well most likely SocketServer will only call your Handler when there is actually something to read, so you have to call read() and handle the input, either by adding it to a buffer (for example if it doesn't end in a '.' meaning there is more data to be read) and let the socket server take care of the looping. <2> DraX: So you call recv once handle the result and then let the function exit, if there is more data to read the SocketServer will call your handler again <0> so getting rid of the loop may just fix it? <2> DraX: if your recv buffer is big enough <2> DraX: if your pickles are small it should work fine, but i wouldn't recomend it as a solution <2> DraX: do you understand the problem now though? <0> to some degree. <2> well thats the most important part <0> bleh <0> now it only receives the first command <2> anyway you could pastebin this? or is it too big <2> are you looking at what is .recv() or are you just trying to unpickle it right away <0> graham_: same problem either way <0> but i switched back to reading right off the socket. <2> DraX: ok but you get a string that ends in a '.' right? <0> yeah <2> DraX: try printing the data that you read from teh socket <2> and when you leave the function it just hangs out? <0> ok, handle only gets called for the first command <2> hrm <0> http://63c09743bf18b4ef.paste.se/ <2> any chance the other commands arn't getting sent? <0> the daemon <0> http://7769a40da0e91269.paste.se/ <0> the client <0> graham_: the commands are going out. <2> DraX: alright it looks like this is a threaded server so you want to have a loop in the handler <2> and making it non_blocking or reducing the blocking time shouldn't affect the socket server <0> graham_: it needs to be threaded (or forking) or multiple clients can't connect <2> DraX: sorry i forgot how SocketServer did its thing <2> DraX: thats not totally true. Take a look at the 'select' module <2> DraX: its true if your in Java, but C provides much better tools <3> java has async IO these days too <2> why there is no 'select' in java i can't understand <2> async I/O seems like a waste most of the time <3> java.nio.Selector etc... <2> joedj: i'll have to check on that, perhaps its just that as soon as you talk about handling multiple clients everyone just uses threads <3> yeah, it's a reall PITA to use (not worse than threads, but...) <3> there's a nice little async framework done by itamar around nio called 'eio' <5> shouldn't i be able to compare a list, for example lets say i have li = ['sometext', 'someothertext', 'etc...'] <2> joedj: i think that for some things async i/o is needed, but for things like a little chat server, or a mud or something select is the way to go, btw thanks for the Selector note, now i can't bash on java nearly as much. <5> shoudln't i be able to compare: if li[0] == 'sometext':?' <2> what is li? <3> graham_: select is generally what i mean when i talk about async io :) <5> just told you a list =) <0> graham_: so should i select(1, [], []) ...? <3> Noet: yes <2> DraX: then you have to know a bit more about sockets, i would stick with your loop <0> graham_: i still have this bug though :) <2> joedj: pardon, i got mixed up typing async/sync <0> interestingly enough the first two commands are being executed now <0> instead of only the first <2> DraX: and you haven't changed anything? <2> DraX: or your looping now <0> graham_: i must have changed something <0> i'm looping now <0> but i was looping before <2> ok <0> and only the first command worked <0> i must have changed something <0> when i put the loop back in <2> DraX: Sorry could you paste again what you are workin with now? <0> graham_: sure <5> joedj, well i get Index out of range :/ <5> after i have called a re.findall() function, i have looked so i know that everything is in there. <2> Noet: then your "li" isn't a tuple/list it doesn't have elements. <5> its just that i can't compare with if <0> client: http://1aa21b35b954c167.paste.se/ <5> graham_, well it is a list, even the document abotu re.findall() says it returns a list <3> Noet: if L[0] gives you an IndexError, then L is empty <2> what is gobject? <5> joedj, it isn't, i have printed it out. i got: <0> http://3a14613326914ae6.paste.se/ - server
Return to
#python or Go to some related
logs:
umbumtu gentoo zmysqlda ImportError: No module named _mysql #mysql gyach quits
#math #oe could not grab your mouse ubuntu #sed amount of cafeine in tea #linux
|
|