Re: How to reuse TCP listening socket immediately after it was connected at least once?

2009-05-30 Thread Thomas Bellman
Lawrence D'Oliveiro wrote: > In message , Thomas Bellman wrote: >> Speaking as a sysadmin, running applications for production, >> programs not using SO_REUSEADDR should be taken out and shot. >> Not using SO_REUSEADDR means forcing a service interruption of >>

Re: How to reuse TCP listening socket immediately after it was connected at least once?

2009-05-28 Thread Thomas Bellman
nclosed, no matter what you do. Not using SO_REUSEADDR means forcing a service interruption of half an hour (IIRC) if for some reason the service must be restarted, or having to reboot the entire machine. No thanks. I have been in that situation. -- Thomas Bellman, Lysator Academic Computer

Re: named pipe and Linux

2009-04-08 Thread Thomas Bellman
message with an octet sequence that cannot occur within a message. For example, a linefeed without a backslash before it (and you would probably want a way to escape the backslash, in case you want to end a message with a backslash). - Have small header of a fixed size at the start of eac

Re: Hash of None varies per-machine

2009-04-04 Thread Thomas Bellman
Steven D'Aprano wrote: > You can hash numbers no matter how big they are. > >>> hash(float('inf')) > 314159 Cute. And hash(float('-inf')) is -271828... -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "God is

Re: Need help with os.system in linux

2009-01-17 Thread Thomas Bellman
erface for running external commands. For example, you can avoid having to deal with quoting shell metacharacters, and interpreting the return values are easier. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "Life IS pain, highness. Anyone who tells

Re: Security implications of using open() on untrusted strings.

2008-11-24 Thread Thomas Bellman
s one thing to let the user overwrite a file named "foo; rm -rf $HOME", quite another to pass that string unquoted to /bin/sh when the user thought he was just typing a filename.) -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "I don't think [tha

Re: sorting list of complex numbers

2008-11-11 Thread Thomas Bellman
ython-coded function at all. The operator module is your friend: key=operator.attrgetter('real', 'imag') will create the required tuples for sorting. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "God is real, but Jesus is

Re: subprocess.Popen(..., cwd=...) and Makefile $(PWD) don't play nice

2008-10-14 Thread Thomas Bellman
(not all!) shells. It should not be trusted outside those shells, and hardly inside them either. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "Adde parvum parvo magnus acervus erit" ! bellman @ lysator.liu.se (From The Mythic

Re: subprocess.Popen(..., cwd=...) and Makefile $(PWD) don't play nice

2008-10-07 Thread Thomas Bellman
find the Makefile at /tmp/p if the current > directory were another one... (?) The problem is, he is not printing the name of the current working directory; he is printing the value of the variable $PWD. That is likely set from the environment by the shell he started the Python program from,

Re: max(), sum(), next()

2008-09-04 Thread Thomas Bellman
t an illogical stance to take. It's just a totally different issue from encountering a non-numeric element in the sequence. In some cases it might actually make sense to treat the empty sequence as an error, but just ignore non-numeric elements (i.e, treat them as if they were zero).

Re: max(), sum(), next()

2008-09-04 Thread Thomas Bellman
ad) does return NULL for a sum over the empty sequence, so you could argue that that would be the correct behaviour for the Python sum() function as well, but you can't argue that because a sum *involving* a NULL value returns NULL. -- Thomas Bellman, Lysator Computer Club, Linköping U

Re: Exit from os.chroot()

2008-06-05 Thread Thomas Bellman
symlinks from the chroot jail that try to point to things outside the chroot, you are at least guaranteed that you won't give the chroot:ed process to much information. Unfortunately, you won't be giving it the tools it needs to do its designed job, either, since symlinks can't esca

Re: Exit from os.chroot()

2008-06-04 Thread Thomas Bellman
cess can do even when chroot:ed, like creating device files or setuid binaries. All this is of course assuming that the chroot is done for security reasons. There are other reasons one might want to run in chroot. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden

Re: defaultdict.fromkeys returns a surprising defaultdict

2008-06-04 Thread Thomas Bellman
27;], 0) >>> d.default_factory = list >>> d defaultdict(, {'y': 0, 'x': 0}) >>> d['z'] [] >>> d defaultdict(, {'y': 0, 'x': 0, 'z': []}) The keys you give to the fromkeys() method

Re: Accumulating values in dictionary

2008-05-20 Thread Thomas Bellman
his, then I believe the warning I gave about performance does not apply; my understanding is that calling built-in functions (like the int constructor) is fast. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "Beware of bugs in the above code; I have! be

Re: Misuse of list comprehensions?

2008-05-20 Thread Thomas Bellman
ntain the list. Unlikely, but not entirely impossible, and just a small change of the problem size can change the balance again. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "What sane person could live in this world ! bellman @ lysator.liu.se and not be crazy?" -- Ursula K LeGuin ! Make Love -- Nicht Wahr! -- http://mail.python.org/mailman/listinfo/python-list

Re: Accumulating values in dictionary

2008-05-20 Thread Thomas Bellman
en to defaultdict will be called the first time a key is mentioned, and if the keys are mostly unique, that will be the majority of the times, and calling a pure Python function is fairly slow in CPython. (It probably won't matter unless you have many thousands of unique keys, though.) -- Thom

Re: Misuse of list comprehensions?

2008-05-20 Thread Thomas Bellman
t you *also* create a 17 long list with all elements set to None, that is immediately thrown away. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "I refuse to have a battle of wits with an ! bellman @ lysator.liu.se unarmed person."! Make Love -- Nicht Wahr! -- http://mail.python.org/mailman/listinfo/python-list

Re: How to kill Python interpreter from the command line?

2008-05-10 Thread Thomas Bellman
Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: >(Ctrl+Z which sends SIGSTOP and _cannot_ be masked > or otherwise ignored) Bzzt! Ctrl-Z causes a SIGTSTP to be sent, not SIGSTOP, and SIGTSTP can be both caught, ignored and masked. -- Thomas Bellman, Lysator C

Re: Python 2.5 adoption

2008-04-18 Thread Thomas Bellman
e using. And RHEL/CentOS 4 is still quite common, so if you want to reach a large "customer base", make sure that your Python programs work with Python 2.3. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "Don't tell me I'm burning the candle

Re: network programming: how does s.accept() work?

2008-02-25 Thread Thomas Bellman
be more or less random, but it will make sure that the four-tuple identifying the TCP connection will be unique. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "There are many causes worth dying for, but ! bellman @ lysator.liu.se none worth killing for.&

Re: Why does list have no 'get' method?

2008-02-07 Thread Thomas Bellman
Scheme? If so, then no, in Scheme only #f is false, and the empty list () is considered true. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "When C++ is your hammer, everything ! bellman @ lysator.liu.se looks like a thumb."

Re: polling for output from a subprocess module

2008-02-06 Thread Thomas Bellman
Ivo <[EMAIL PROTECTED]> wrote: > Thomas Bellman wrote: >> However, the os.read() function will only read what is currently >> available. Note, though, that os.read() does not do line-based >> I/O, so depending on the timing you can get incomplete lines, or &g

Re: polling for output from a subprocess module

2008-02-05 Thread Thomas Bellman
Christian Heimes <[EMAIL PROTECTED]> writes: > Thomas Bellman wrote: >> The readlines() method will read until it reaches end of file (or >> an error occurs), not just what is available at the moment. You >> can see that for your self by running: > Bad idea ;) W

Re: polling for output from a subprocess module

2008-02-04 Thread Thomas Bellman
hink, Ctrl-Z if you are using MS-Windows). However, the os.read() function will only read what is currently available. Note, though, that os.read() does not do line-based I/O, so depending on the timing you can get incomplete lines, or multiple lines in one read. -- Thomas Bellman, Lysat

Re: read and readline hanging

2008-01-27 Thread Thomas Bellman
> Yes but my python threading is worse than rudimentary. I will look > into the `trheading` module suggested by the other poster. I think you would be better off looking into the correctly spelled 'threading' module rather than the misspelled 'trheading' module. :-) -- Th

Re: read and readline hanging

2008-01-25 Thread Thomas Bellman
there is a space instead of a dash after the "250" code in the last line above, the SMTP client knows that there won't be any more lines in response to its command. If you can't get the program you are calling to follow some protocol like this, then you can only make guesses.

Re: spawning a process with subprocess

2007-11-27 Thread Thomas Bellman
of "cat" as a test program, I suppose that isn't a problem for you. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "God is real, but Jesus is an integer." ! bellman @ lysator.liu.se ! Make Love -- Nicht Wahr! -- http://mail.python.org/mailman/listinfo/python-list

Re: eof

2007-11-22 Thread Thomas Bellman
files, but on pipes, sockets or terminals, you would have major problems, since suddenly calling the eof() method would block the process. Probably not what you were expecting. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "Life IS pain, highness. Anyone who te

Re: An expression that rebinds a variable?

2007-05-18 Thread Thomas Bellman
x27; is the expression List comprehensions: >>> c Traceback (most recent call last): File "", line 1, in NameError: name 'c' is not defined >>> eval('[ord(c) for c in "parrot"]') [112, 97, 114, 114, 111, 116] >&g

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-18 Thread Thomas Bellman
erently that for example a Japanese person will not be able to recognize a character rendered in the Taiwanese or mainland Chinese way. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "Adde parvum parvo magnus acervus erit" ! bellman @ lysator.liu

Re: Get Shift + TAB in ncurses.

2007-04-12 Thread Thomas Bellman
but that will only apply to your terminal, not to anyone else's. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "Don't tell me I'm burning the candle at both ! bellman @ lysator.liu.se ends -- tell me where to get more wax!!" ! Make Lo

Re: Prevent Modification of Script?

2007-04-05 Thread Thomas Bellman
(Don't feel too bad about it. I have made similar mistakes myself, but after many years working with computer security I have managed to learn not to do *that* particular error again; I hope...) -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "Life IS pai

Re: How to suppress "DeprecationWarning: Old style callback, use cb_func(ok, store) instead"

2007-02-06 Thread Thomas Bellman
for the same #! line. I seem to remember having used some Unix flavor that allowed multiple words as arguments, and thus passed the four words "foo", "bar", "gazonk" and "del" as arguments for the above #! line, but I don't remember what Uni

Re: Need help with an array problem.

2006-10-03 Thread Thomas Bellman
printf("Pointer cast: %d %10.6f\n", *(int*)&f, *(float*)&i); to the program. It should output the same numbers as the "Bitcopy" printf(). But what is cast here is the *address* of the variables, not the actual contents of them. It is the *dereferencing* of thos

Re: simplexmlrpcserver and allow_none

2006-06-08 Thread Thomas Bellman
gs, **kwargs): kwargs.setdefault('allow_none', 1) return self.__dumps[0](*args, **kwargs) xmlrpclib.dumps = _xmldumps(xmlrpclib.dumps) import SimpleXMLRPCServer -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "

Re: Problem calling math.cos()

2006-04-23 Thread Thomas Bellman
Alex Martelli <[EMAIL PROTECTED]> wrote: > C has no stand on complex numbers. If by that you mean that C does not have complex numbers, then you are wrong. C99 defines the three types float _Complex, double _Complex, and long double _Complex, and also the header . -- Thoma

Re: how relevant is C today?

2006-04-10 Thread Thomas Bellman
Lawrence D'Oliveiro <[EMAIL PROTECTED]> writes: > "const" is in C89/C90. Although with slightly different semantics from in C++... For instance: static const int n = 5; double a[n]; is valid C++, but not valid C. -- Thomas Bellman, Lysator Computer Club

Re: How do I use the subprocess module with mswindows?

2006-03-19 Thread Thomas Bellman
subprocess without deadlocking, you may be helped by using my asyncproc module, which you can download from http://www.lysator.liu.se/~bellman/download/asyncproc.py I suspect that it only works on Unix, though. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden &q

Re: writing large files quickly

2006-01-29 Thread Thomas Bellman
zeros 65M zeros (You can infer from the above that my file system has a block size of 4 Kbyte.) -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "There are many causes worth dying for, but ! bellman @ lysator.liu.se none worth killing for."

Re: Testing for the presence of input from stdin.

2006-01-24 Thread Thomas Bellman
to read, you will terminate prematurely in many cases. Even 'dd if=/dev/zero | myprogram.py' will stop at some random point, when the OS happens to decide that myprogram.py should be scheduled twice without dd getting the chance to fill the pipe buffer inbetween. -- Thomas Bellman, Ly

Re: append to non-existing list

2005-11-09 Thread Thomas Bellman
ee it is much more work than to do it the right way. It's also much more fragile; think for example about what happens if your SQL statement (I assume that's what sqlsth is) yields zero rows, and you then try to look at pkcolumns after that loop. -- Thomas Bellman, Lysator Computer Club,

Re: process and spinning slash

2005-10-30 Thread Thomas Bellman
e child process was started using subprocess.Popen, you should usually use the poll() methods on the Popen object to check if the process has terminated. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "You are in a twisty little passage of ! bellman @ lysator

Re: Python Doc Error: os.makedirs

2005-10-19 Thread Thomas Bellman
s.makedirs("/tmp/trh/spam/norwegian/blue/parrot/cheese") except os.error, e: if ( e.errno != errno.EEXIST or not os.path.isdir("/tmp/trh/spam/norwegian/blue/parrot/cheese")): raise -- Thomas Bellman, Lysator Computer Club, Linköping Uni

Re: Python Doc Error: os.makedirs

2005-10-19 Thread Thomas Bellman
o the function. Thus, this gives you the behaviour you want: try: os.makedirs("/tmp/trh/spam/norwegian/blue/parrot/cheese") except os.error, e: if e.errno != errno.EEXIST: raise -- Thomas Bellman, Lysator Computer Club, Linköping University,

Re: subprocess and non-blocking IO (again)

2005-10-11 Thread Thomas Bellman
7;t use that OS, and thus can't test it. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "Beware of bugs in the above code; I have! bellman @ lysator.liu.se only proved it correct, not tried it." ! Make Love -- Nicht Wahr! -- http://mail.python.org/mailman/listinfo/python-list

Re: determine if os.system() is done

2005-09-07 Thread Thomas Bellman
s"), but i wish to know if there's non-hack way to > determine when a system process is done. Have you tried reading the manual for the subprocess module? You just *might* find the answer to your question if you look at what you can do with Popen objects. Actually, just learning about

Re: dual processor

2005-09-06 Thread Thomas Bellman
ble in comparison, and would likely fit within the slots when 'md5sum' is waiting for I/O even on a single-CPU system. And I'm fairly certain that 'sort' won't start spending CPU time until it has collected all its input, so you won't gain much there either. -- T

Re: Trouble saving unicode text to file

2005-05-11 Thread Thomas Bellman
=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= <[EMAIL PROTECTED]> wrote: >Thomas Bellman wrote: >> Fixed-with characters *do* have advantages, even in the external >> representation. With fixed-with characters you don't have to >> parse the entire file or stream in

Re: Trouble saving unicode text to file

2005-05-10 Thread Thomas Bellman
o an octet position that can be calculated directly from N. In-place editing of single characters in large files becomes more efficient. The codec for UTF-32 is extremely simple. There are no illegal sequences to care about, like there are in UTF-8 and UTF-16, just illegal single 32-bit values (those

Re: Trouble saving unicode text to file

2005-05-10 Thread Thomas Bellman
compatible with ASCII (the way UTF-8 is), nor uses fixed-with characters (like UTF-32 does)? -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "You are in a twisty little passage of ! bellman @ lysator.liu.se standards, all conflicting."!

Re: How to use subprocess

2005-03-23 Thread Thomas Bellman
lass. It doesn't do exactly what you want, but maybe you can use it as inspiration for doing it yourself. It requires the subprocess module, but I have successfully used it under Python 2.3.2 with subprocess installed locally. -- Thomas Bellman, Lysator Computer Club, Linköping Univer

Re: Python becoming less Lisp-like

2005-03-17 Thread Thomas Bellman
t it's not really fair to say "ignore it > and it won't affect you" -- there's still a cost associated with such > features that can't be ignored away. There is a "local" cost with it, for learning Python, but I'm not sure there really is

Re: Python becoming less Lisp-like

2005-03-15 Thread Thomas Bellman
r using the package. If some authors write bad books, do you blame the English language for allowing them to write such books, or do you blame the writers for using English in a bad way? -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "We don't understand

Re: pre-PEP: Print Without Intervening Space

2005-03-15 Thread Thomas Bellman
parrot() with a one-element tuple either. However, 'parrot(1)' and 'parrot(1,)' means exactly the same thing, while 'print 1' and 'print 1,' does not. -- Thomas Bellman, Lysator Computer Club, Linköping University, Sweden "Adde parvum parvo magnus