Re: L[:]

2014-01-13 Thread Laszlo Nagy
Unless L is aliased, this is silly code. There is another use case. If you intend to modify a list within a for loop that goes over the same list, then you need to iterate over a copy. And this cannot be called an "alias" because it has no name: for idx,item in enumerate(L[:]): # do somet

Re: Cracking hashes with Python

2013-11-27 Thread Laszlo Nagy
On 2013-11-26 00:58, Marc wrote: Hashes, by definition, are not reversible mathematically. The only way to figure out what they represent is to take plaintext that might be the plaintext based on anything you might know about the original plaintext (which is often nothing) and hash it; then see

Re: Method chaining

2013-11-23 Thread Laszlo Nagy
OK, that one is disgusting... Anyway, I'd like to see a sequence of method names taken from actual code that profits from this chaining pattern. Actually, wx.lib.agw uses this a lot. Especially for AuiPaneInfo: http://www.wxpython.org/docs/api/wx.aui.AuiPaneInfo-class.html All right, this

Doc generation from annotated source code

2013-11-18 Thread Laszlo Nagy
I just started rewritting my project from python 2 to python 3. I noticed that there are these new parameter and return value annotations. I have docstrings everywhere in my project, but I plan to convert many of them into annotations. The question is: what kind of auto documenting system shoul

inconsistency in converting from/to hex

2013-11-16 Thread Laszlo Nagy
We can convert from hex str to bytes with bytes.fromhex class method: >>> b = bytes.fromhex("ff") But we cannot convert from hex binary: >>> b = bytes.fromhex(b"ff") Traceback (most recent call last): File "", line 1, in TypeError: must be str, not bytes We don't have bytes_instance.tohex()

Re: Beginner python 3 unicode question [SOLVED]

2013-11-16 Thread Laszlo Nagy
So is the default utf-8 or not? Should the documentation be updated? Or do we have a bug in the interactive shell? It was my fault, sorry. The other program used os.system at some places, and it accidentally used python2 instead of python 3. :-( -- This message has been scanned for viruse

Re: Beginner python 3 unicode question

2013-11-16 Thread Laszlo Nagy
Why it is behaving differently on the command line? What should I do to fix this? I was experimenting with this a bit more and found some more confusing things. Can somebody please enlight me? Here is a test function: def password_hash(self,password): public = bytearray([rando

Re: Beginner python 3 unicode question

2013-11-16 Thread Laszlo Nagy
the error is in one of the lines you did not copy here because this works without problems: <> #!/usr/bin/python Most probably, your /usr/bin/python program is python version 2, and not python version 3 Try the same program with /usr/bin/python3. And also try the interactive mode with

Re: Asyncmongo and Python3: ImportError: No module named 'errors'

2013-11-16 Thread Laszlo Nagy
Sorry if this question was answered before, I'm new to Python 3. Have you seen and met its 'requirements'? If you haven't then perhaps that's the problem. Yes I did. Requirements are: pymongo 1.9+ and tornado. Both are compatible with Python 3 and are installed on my system: gandalf@gandalf

Why tornado.web.RequestHandler.arguments.get is binary?

2013-11-16 Thread Laszlo Nagy
I believe most data passed in URLs are character data. RFC 2986 also suggest that the standard should be percent encoded UTF-8: The generic URI syntax mandates that new URI schemes that provide for the representation of character data in a URI must, in effect, represent characters from the unr

Beginner python 3 unicode question

2013-11-16 Thread Laszlo Nagy
Example interactive: $ python3 Python 3.3.1 (default, Sep 25 2013, 19:29:01) [GCC 4.7.3] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import uuid >>> import base64 >>> base64.b32encode(uuid.uuid1().bytes)[:-6].lower() b'zsz653co6ii6hgjejqhw42ncgy' >>> But w

Asyncmongo and Python3: ImportError: No module named 'errors'

2013-11-16 Thread Laszlo Nagy
I'm about to convert a complete library into python3. I need asnycmongo for this. Trying to install it on Ubuntu. After executing "sudo pip3 install asyncmongo" I have the following traceback: Traceback (most recent call last): ... import asyncmongo File "/usr/local/lib/python3.3/

Re: Encoding problem in python

2013-03-04 Thread Laszlo Nagy
On 2013-03-04 10:37, yomnasala...@gmail.com wrote: I have a problem with encoding in python 27 shell. when i write this in the python shell: w=u'العربى' It gives me the following error: Unsupported characters in input any help? Maybe it is not Python related. Did you get an exception? Can yo

Re: Is there a graphical GUI builder?

2013-02-20 Thread Laszlo Nagy
You have to think about your window differently - think about what you're putting where, rather than going visually "that looks about right" - but the reward is that it'll look right no matter where you run your app. As an added bonus, you don't need any sort of graphical builder; you can just w

Re: using smtp sent large file upto 60MB

2012-12-04 Thread Laszlo Nagy
Thank for suggestion. The next task will be ftp to user folder. But first tasks is how to using python send huge files. Most SMTP servers are configured not to accept attachments bigger than 10 or 15MB. In general, you should never send emails with >5MB attachments. Not because it is not possi

Re: SSH Connection with Python

2012-10-25 Thread Laszlo Nagy
On 2012-10-25 12:16, Schneider wrote: Hi Folkz, how can i create a SSH-Connection with python? I have to send some commands to the remote host and parse their answers. greatz Johannes http://www.lag.net/paramiko/ Another solution would be to use subprocess and/or pexpect -- http://mail.pyth

Re: bad httplib latency due to IPv6 use

2012-10-17 Thread Laszlo Nagy
What I'm wondering is this: 1. The server only serves on IPv4, changing this to IPv6 would probably help. However, I wouldn't consider this a bug, or? I'd say it's a bug in your TCP/IP stack. An IP shouldn't take that long to figure out that it is not configured to connect to IPv6 addresses. I

Re: how to build Object for List data

2012-10-08 Thread Laszlo Nagy
Seq validation 1 Program3,1,3,4 # max(F1,F3) to F4 .. n How to using python to Read the text file, Build the data as object class ? Open the file using the open() command. Then iterate over the lines within a stateful algorithm that parses the lines with regular expressions. Wh

Re: Reading properties file in Python, except using ConfigParser()

2012-10-05 Thread Laszlo Nagy
On 2012-10-05 09:20, justmailha...@gmail.com wrote: Hi All, How to read properties file in Python? I found ConfigParser() but it has a 'section' limitation, so looking for other alternatives. http://wiki.python.org/moin/ConfigParserShootout -- http://mail.python.org/mailman/listinfo/python-li

Re: howto handle nested for

2012-09-28 Thread Laszlo Nagy
On 2012-09-28 16:39, Neal Becker wrote: I know this should be a fairly basic question, but I'm drawing a blank. I have code that looks like: for s0 in xrange (n_syms): for s1 in xrange (n_syms): for s2 in xrange (n_syms): for s3 in xrange (n_syms):

Module baldy compiled to pyc?

2012-09-27 Thread Laszlo Nagy
Today I had a strange experience. I have copied some updated py files (modules) to a directory on a remote server, overwritting the old ones. The pyc files on the server were older. Many programs are importing these modules, and most of them are started as background jobs (from cron). They star

Re: how to do draw pattern with python?

2012-09-21 Thread Laszlo Nagy
On 2012-09-21 15:36, echo.hp...@gmail.com wrote: may i know how to shift the bits using only looping and branching?? xx .x..x. ..xx.. ..xx.. .x..x. xx What kinds of bits? What are these points and x-es anyway? Are they strings? Or binary data? I recommend this for reading: http:

Re: reportlab and python 3

2012-09-18 Thread Laszlo Nagy
I understood, you have Python on a platform and starting from this you wish to create pdf files. Obviously, embedding "TeX" is practically a no solution, although distibuting a portable standalone TeX distribution is a perfectly viable solution, especially on Windows! To "I wanted to learn TeX

Re: reportlab and python 3

2012-09-18 Thread Laszlo Nagy
A big yes and it is very easy. I assume you know how to write a plain text file with Python :-). Use your Python to generate a .tex file and let it compile with one of the pdf TeX engines. Potential problems: - It requires a TeX installation (a no problem). - Of course I requires some TeX know

reportlab and python 3

2012-09-17 Thread Laszlo Nagy
Reportlab is on the wall of shame. http://python3wos.appspot.com/ Is there other ways to create PDF files from python 3? There is pyPdf. I haven't tried it yet, but it seem that it is a low level library. It does not handle "flowables" that are automatically split across pages. It does not han

Re: Moving folders with content

2012-09-17 Thread Laszlo Nagy
On 2012-09-15 06:36, jyoun...@kc.rr.com wrote: Hello, I am working in both OS X Snow Leopard and Lion (10.6.8 and 10.7.4). I'm simply wanting to move folders (with their content) from various servers to the hard drive and then back to different directories on the servers. I want to be careful n

Re: What's wrong with my arc tangens calculation?

2012-09-14 Thread Laszlo Nagy
but when i lookup tg in a paper table (last decade math book) i've got these values: tg(63'10'') = 1.9768 tg(63'20'') = 1.9912 tg(63'30'') = 2.0057 For me python should return something more like 63'2x'' than 63'4x''(becasue 63'30'' is higher than 2.0) what's wrong? 63° 30" is 63.5°. So n

Re: submit jobs on multi-core

2012-09-10 Thread Laszlo Nagy
On 2012-09-11 06:16, Dhananjay wrote: Dear all, I have a python script in which I have a list of files to input one by one and for each file I get a number as an output. I used for loop to submit the file to script. My script uses one file at a time and returns the output. My computers has 8

Re: Looking for an IPC solution

2012-09-06 Thread Laszlo Nagy
Probably the fastest I/RPC implementation for Python should be OmniOrbpy: http://omniorb.sourceforge.net/ It's cross-platform, language-independent and standard-(Corba-) compliant. I don't want to use IDL though. Clients will be written in Python, and it would be a waste of time to write IDL

Re: Looking for an IPC solution

2012-09-06 Thread Laszlo Nagy
Hi Laszlo, There aren't a lot of ways to create a Python object in an "mmap" buffer. "mmap" is conducive to arrays of arrays. For variable-length structures like strings and lists, you need "dynamic allocation". The C functions "malloc" and "free" allocate memory space, and file creation a

Re: Looking for an IPC solution

2012-09-06 Thread Laszlo Nagy
How about the standard multiprocessing module? It supports shared memory, remote processes, and will most probably work under PyPy: http://docs.python.org/library/multiprocessing.html I always thought, that the multiprocessing module does NOT use shared memory (at least not under windows) It

Re: Error 32 - Broken Pipe . Please Help!!

2012-09-04 Thread Laszlo Nagy
2012.09.04. 19:08 keltezéssel, Sreenath k írta: Error: Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner self.run() File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/monitor.py

Re: tornado.web ioloop add_timeout eats CPU

2012-09-04 Thread Laszlo Nagy
What's wrong is the 1,135,775 calls to "method 'poll' of 'select.epoll' objects". I was affraid you are going to say that. :-) With five browsers waiting for messages over 845 seconds, that works out to each waiting browser inducing 269 epolls per second. Almost equally important is what the

tornado.web ioloop add_timeout eats CPU

2012-09-02 Thread Laszlo Nagy
JavaScript clients (browsers) do long poll requests. Each request can take up to 10 seconds before the server responds. On the server side, every client has a queue of messages that needs to be sent to the client. When the long poll request comes in, the server checks if there are messages to b

Re: Async client for PostgreSQL?

2012-09-02 Thread Laszlo Nagy
Hmm, I was suggesting that you could replace the whole DB driver with a webservice implemented with twisted, if you rule out threads then with ampoule doing it with a process pool and consume this webservice with the tornado side asynchronously. I see. I'm sorry, I misunderstood. So this would

Re: Async client for PostgreSQL?

2012-09-01 Thread Laszlo Nagy
Hi does running on tornado imply that you would not consider twisted http://twistedmatrix.com ? If not, twisted has exactly this capability hiding long running queries on whatever db's behind deferToThread(). All right, I was reading its documentation http://twistedmatrix.com/documents/10

Re: to know binary

2012-09-01 Thread Laszlo Nagy
On 2012-09-01 06:15, contro opinion wrote: there is a only line in the file nanmed test: 1234 when i open it whit xxd xxd test what i get is : 000: 3132 3334 0a 1234. can you explain it ? At offset zero (00): chr(0x31) + chr(0x32)+ chr(0x33)+ chr(0x33)+ chr

Async client for PostgreSQL?

2012-08-31 Thread Laszlo Nagy
Is there any extension for Python that can do async I/O for PostgreSQL with tornadoweb's ioloop? Something like: class MainHandler(tornado.web.RequestHandler): @tornado.web.asynchronous def get(self): pg_connection.(long_taking_query_sql,params,callback=self.on_query_opened)

Re: Looking for an IPC solution

2012-08-31 Thread Laszlo Nagy
Zeromq (suggested by someone) is an option since it's pretty fast for most purposes, but I don't think it uses shared memory. Interesting question. The documentation says: http://api.zeromq.org/2-1:zmq-ipc The inter-process transport is currently only implemented on operating systems that prov

Looking for an IPC solution

2012-08-31 Thread Laszlo Nagy
There are just so many IPC modules out there. I'm looking for a solution for developing a new a multi-tier application. The core application will be running on a single computer, so the IPC should be using shared memory (or mmap) and have very short response times. But there will be a tier that

Re: Extract Text Table From File

2012-08-27 Thread Laszlo Nagy
On 2012-08-27 13:23, Huso wrote: Hi, There can be any number of blocks in the log file. I distinguish the block by the start header 'ROUTES TRAFFIC RESULTS, LSR' and ending in 'END'. Each block will have a unique [date + time] value. I tried the code you mentioned, it works for the data part.

Re: Extract Text Table From File

2012-08-27 Thread Laszlo Nagy
Hi, Thank you for the information. The exact way I want to extract the data is like as below. TRG, MP and DATE and TIME is common for that certain block of traffic. So I am using those and dumping it with the rest of the data into sql. Table will have all headers (TRG, MP, DATE, TIME, R, TRAFF

Re: Extract Text Table From File

2012-08-27 Thread Laszlo Nagy
On 2012-08-27 11:53, Huso wrote: Hi, I am trying to extract some text table data from a log file. I am trying different methods, but I don't seem to get anything to work. I am kind of new to python as well. Hence, appreciate if someone could help me out. # # Write test data to test.txt # da

Re: something about split()???

2012-08-24 Thread Laszlo Nagy
On 2012-08-15 07:33, Ramchandra Apte wrote: filter is bad when you use lambda with it there are (good) cases for filter On 14 August 2012 22:39, Jean-Michel Pichavant > wrote: Ramchandra Apte wrote: (Much) more Pythonic solution: >>> filter(N

Re: Does a wxPython program not run on 64bit Windows?

2012-08-24 Thread Laszlo Nagy
On 2012-08-24 07:37, Levi Nie wrote: Does a wxPython program not run on 64bit Windows? Did you at least try to download wxPython? Because the download page shows the 64bit and the 32bit versions as well. :-) http://wxpython.org/download.php By the way, the 32bit version will gladly run on a

Re: Guarding arithmetic

2012-08-23 Thread Laszlo Nagy
def safe(deferred, default=42, exception=Exception): ... try: ... return deferred() ... except exception: ... return default What a beautiful solution! I was wondering if the following would be possible: def test(thing, default, *exc_classes): try:

Re: Guarding arithmetic

2012-08-23 Thread Laszlo Nagy
On 2012-08-23 11:05, Mark Carter wrote: Suppose I want to define a function "safe", which returns the argument passed if there is no error, and 42 if there is one. So the setup is something like: def safe(x): # WHAT WOULD DEFINE HERE? print safe(666) # prints 666 print safe(1/0) # prints 4

Re: Guarding arithmetic

2012-08-23 Thread Laszlo Nagy
That can work ONLY if the division of 1/0 doesn't raise an exception. This is why the concept of NaN exists; I'm not sure if there's a way to tell Python to return NaN instead of bombing, but it's most likely only possible with floating point, not integer. For integers, Python will always raise

Re: Why doesn't Python remember the initial directory?

2012-08-19 Thread Laszlo Nagy
On 2012-08-19 22:42, kj wrote: As far as I've been able to determine, Python does not remember (immutably, that is) the working directory at the program's start-up, or, if it does, it does not officially expose this information. Does anyone know why this is? Is there a PEP stating the rational

Re: type(None)()

2012-08-16 Thread Laszlo Nagy
On 2012-08-16 14:47, Hans Mulder wrote: On 8/08/12 04:14:01, Steven D'Aprano wrote: NoneType raises an error if you try to create a second instance. bool just returns one of the two singletons (doubletons?) again. py> type(None)() Traceback (most recent call last): File "", line 1, in TypeE

Re: I thought I understood how import worked...

2012-08-07 Thread Laszlo Nagy
On 2012-08-08 06:14, Ben Finney wrote: Cameron Simpson writes: All of you are saying "two names for the same module", and variations thereof. And that is why the doco confuses. I would expect less confusion if the above example were described as _two_ modules, with the same source code. That

Re: I thought I understood how import worked...

2012-08-07 Thread Laszlo Nagy
On 2012-08-07 15:55, Ben Finney wrote: Roy Smith writes: So, it appears that you *can* import a module twice, if you refer to it by different names! This is surprising. The tutorial is misleading on this. It it says plainly: A module can contain executable statements as well as function

Re: CRC-checksum failed in gzip

2012-08-02 Thread Laszlo Nagy
One last thing I would like to do before I add this fix is to actually be able to reproduce this behaviour, and I thought I could just do the following: import gzip import threading class OpenAndRead(threading.Thread): def run(self): fz = gzip.open('out2.txt.gz') fz.rea

Re: CRC-checksum failed in gzip

2012-08-02 Thread Laszlo Nagy
Technically, that is correct, but IMHO its complete nonsense to share the file object between threads in the first place. If you need the data in two threads, just read the file once and then share the read-only, immutable content. If the file is small or too large to be held in memory at onc

Re: Pass data to a subprocess

2012-08-01 Thread Laszlo Nagy
I still don't get it. shm_unlink() works the same way unlink() does. The resource itself doesn't cease to exist until all open file handles are closed. From the shm_unlink() man page on Linux: The operation of shm_unlink() is analogous to unlink(2): it removes a shared memory o

Re: CRC-checksum failed in gzip

2012-08-01 Thread Laszlo Nagy
Make sure that file objects are not shared between threads. If that is possible. It will probably solve the problem (if that is related to threads). Well I just have to create a lock I guess right? That is also a solution. You need to call file.read() inside an acquired lock. with lock:

Re: CRC-checksum failed in gzip

2012-08-01 Thread Laszlo Nagy
Thanks a lot, that makes a lot of sense.. I haven't given this detail before because I didn't write this code, and I forgot that there were threads involved completely, I'm just trying to help to fix this bug. Your explanation makes a lot of sense, but it's still surprising that even just read

Re: Pass data to a subprocess

2012-08-01 Thread Laszlo Nagy
Yes, I think that is correct. I don't understand why detaching a child process on Linux/Unix would make IPC stop working. Can somebody explain? It is implemented with shared memory. I think (although I'm not 100% sure) that shared memory is created *and freed up* (shm_unlink() system call)

Re: Pass data to a subprocess

2012-08-01 Thread Laszlo Nagy
things get more tricky, because I can't use queues and pipes to communicate with a running process that it's noit my child, correct? Yes, I think that is correct. I don't understand why detaching a child process on Linux/Unix would make IPC stop working. Can somebody explain? It is implemen

Re: CRC-checksum failed in gzip

2012-08-01 Thread Laszlo Nagy
Thanks a lotl, someone that writes on the file while reading might be an explanation, the problem is that everyone claims that they are only reading the file. If that is true, then make that file system read only. Soon it will turn out who is writing them. ;-) Apparently this file is generat

Re: CRC-checksum failed in gzip

2012-08-01 Thread Laszlo Nagy
- The file is written with the linux gzip program. - no I can't reproduce the error with the same exact file that did failed, that's what is really puzzling, How do you make sure that no process is reading the file before it is fully flushed to disk? Possible way of testing for this kind of e

Re: Pass data to a subprocess

2012-08-01 Thread Laszlo Nagy
On 2012-08-01 12:59, Roy Smith wrote: In article , Laszlo Nagy wrote: Yes, I think that is correct. Instead of detaching a child process, you can create independent processes and use other frameworks for IPC. For example, Pyro. It is not as effective as multiprocessing.Queue, but in return

Re: CRC-checksum failed in gzip

2012-08-01 Thread Laszlo Nagy
very simple right? But sometimes we get a checksum error. Do you have a traceback showing the actual error? - CRC is at the end of the file and is computed against the whole file (last 8 bytes) - after the CRC there is the \ marker for the EOF - readline() doesn't trigger the check

Re: Pass data to a subprocess

2012-08-01 Thread Laszlo Nagy
The most effective IPC is usually through shared memory. But there is no OS independent standard Python module that can communicate over shared memory. It's true that shared memory is faster than serializing objects over a TCP connection. On the other hand, it's hard to imagine anything writte

Re: CRC-checksum failed in gzip

2012-08-01 Thread Laszlo Nagy
On 2012-08-01 12:39, andrea crotti wrote: We're having some really obscure problems with gzip. There is a program running with python2.7 on a 2.6.18-128.el5xen (red hat I think) kernel. Now this program does the following: if filename == 'out2.txt': out2 = open('out2.txt') elif filename ==

Re: Pass data to a subprocess

2012-08-01 Thread Laszlo Nagy
Yes I know we don't care about Windows for this particular project.. I think mixing multiprocessing and fork should not harm, but probably is unnecessary since I'm already in another process after the fork so I can just make it run what I want. Otherwise is there a way to do same thing only us

Re: Pass data to a subprocess

2012-08-01 Thread Laszlo Nagy
Thanks, there is another thing which is able to interact with running processes in theory: https://github.com/lmacken/pyrasite I don't know though if it's a good idea to use a similar approach for production code, as far as I understood it uses gdb.. In theory though I could be able to set up

Re: Pass data to a subprocess

2012-08-01 Thread Laszlo Nagy
As I wrote "I found many nice things (Pipe, Manager and so on), but actually even this seems to work:" yes I did read the documentation. Sorry, I did not want be offensive. I was just surprised that it worked better than I expected even without Pipes and Queues, but now I understand why.. Any

Re: Pass data to a subprocess

2012-07-31 Thread Laszlo Nagy
> I think I got it now, if I already just mix the start before another add, inside the Process.run it won't see the new data that has been added after the start. So this way is perfectly safe only until the process is launched, if it's running I need to use some multiprocess-aware data structur

Re: simplified Python parsing question

2012-07-30 Thread Laszlo Nagy
yeah the problem is also little more complicated than simple parsing of Python code. For example, one example (from the white paper) *meat space blowback = Friends and family [well-meaning attempt] *could that be parsed by the tools you mention? It is not valid Python code. Pygments is ab

Re: simplified Python parsing question

2012-07-30 Thread Laszlo Nagy
I appreciate the help because I believe that once this is working, it'll make a significant difference in the ability for disabled programmers to write code again as well as be able to integrate within existing development team and their naming conventions. Did you try to use pygments? htt

Re: Generating valid identifiers

2012-07-27 Thread Laszlo Nagy
> With 16 ** 10 possible digests, the probability of collision hits 50% at 1234605 tables Actually, I'm using base64 encoding. So it is 64**10. I guess using 6 characters will enough. -- http://mail.python.org/mailman/listinfo/python-list

Re: Generating valid identifiers

2012-07-27 Thread Laszlo Nagy
Unless an attacker can select the field names, in which case they may be able to improve those odds significantly. In the case of MD5, they can possibly improve those odds to 1 in 1, since MD5 is vulnerable to collision attacks. Not so for some (all?) of the SHA hashes, at least not yet, but the

Re: Generating valid identifiers

2012-07-27 Thread Laszlo Nagy
As a side note, the odds of having at least one hash collision among multiple tables are known as the birthday problem. At 4 hex digits there are 65536 possible digests, and it turns out that at 302 tables there is a >50% chance that at least one pair of those names have the same 4-digit digest

Re: Generating valid identifiers

2012-07-26 Thread Laszlo Nagy
* Would it be a problem to use CRC32 instead of SHA? (Since security is not a problem, and CRC32 is faster.) What happens if you get a collision? That is, you have two different long identifiers: a.b.c.d...something a.b.c.d...anotherthing which by bad luck both hash to the same value: a.b.c

Generating valid identifiers

2012-07-26 Thread Laszlo Nagy
I have a program that creates various database objects in PostgreSQL. There is a DOM, and for each element in the DOM, a database object is created (schema, table, field, index and tablespace). I do not want this program to generate very long identifiers. It would increase SQL parsing time, an

Re: Daemon loses __file__ reference after a while.

2012-07-24 Thread Laszlo Nagy
If you use fork(), it drops all file descriptors, and creates new ones - may be then loss the __file__...? I don't think this is the case. He wrote that the process runs for weeks without problems, and code using __file__ is being executed all the time. -- http://mail.python.org/mailman/listi

Re: Daemon loses __file__ reference after a while

2012-07-24 Thread Laszlo Nagy
On 2012-07-24 14:17, ivdn...@gmail.com wrote: Hello all, I have a deamon process that runs for some considerable time (weeks) without any problems. At some point it starts throwing the following exception: File "/some/path/scheduler.py", line 376, in applyrule result = execrule(rule_co

Re: How to represent dates BC

2012-07-24 Thread Laszlo Nagy
On 2012-07-24 12:29, Christian Heimes wrote: Am 24.07.2012 11:55, schrieb Laszlo Nagy: What is the good representation here? Should I implement my own date type? (I wouldn't want to.) JDN [1] is a commonly used format for wide ranges of dates. I've used it in the past to refer to day

How to represent dates BC

2012-07-24 Thread Laszlo Nagy
>>> import datetime >>> old_date = datetime.date(1,12,31) >>> str(old_date) '0001-12-31' >>> one_year = datetime.timedelta(days=365) >>> str(one_year) '365 days, 0:00:00' >>> old_date - 10*one_year Traceback (most recent call last): File "", line 1, in OverflowError: date value out of range >>>

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread Laszlo Nagy
Not really. It doesn't quack like anything. Actually, there is no "it". So we cannot talk about how it quacks. :-D -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit conversion to boolean in if and while statements

2012-07-17 Thread Laszlo Nagy
On 2012-07-17 10:23, Andrew Berg wrote: I don't want that, but I am suggesting that it would be consistent with the idea of "something or nothing". Don't confuse names and objects. You can only test the truth value of objects. If you don't have a name in a namespace, then it means you don't hav

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Laszlo Nagy
This syntax is explicit *enough*. We don't need to be any more explicit. But if you are going to argue that "if obj" is *explicit enough*, then apply your argument consistently to "String"+1.75 also. Why must we be explicit about string conversion BUT not boolean conversion? Can you reduce this

Re: Implicit conversion to boolean in if and while statements

2012-07-16 Thread Laszlo Nagy
... Traceback (most recent quip last): Author: "", line 7, in LogicalFallacyError: "Reductio ad absurdum" Deary deary me Rick. Reductio ad adsurdum is not a fallacy. It is a counter-argument to an argument or claim, by showing that the premise of the original claim leads to an absurd conc

Re: How to safely maintain a status file

2012-07-12 Thread Laszlo Nagy
Windows doesn't suppport atomic renames if the right side exists. I suggest that you implement two code paths: if os.name == "posix": rename = os.rename else: def rename(a, b): try: os.rename(a, b) except OSError, e: if e.errno != 183:

Re: How to safely maintain a status file

2012-07-12 Thread Laszlo Nagy
This is not a contradiction. Although the rename operation is atomic, the whole "change status" process is not. It is because there are two operations: #1 delete old status file and #2. rename the new status file. And because there are two operations, there is still a race condition. I see no co

Re: How to safely maintain a status file

2012-07-12 Thread Laszlo Nagy
Sorry, but you are wrong. It's just one operation that boils down to "point name to a different inode". After the rename op the file name either points to a different inode or still to the old name in case of an error. The OS guarantees that all processes either see the first or second state (in

Re: How to safely maintain a status file

2012-07-12 Thread Laszlo Nagy
Renaming files is the wrong way to synchronize a crawler. Use a database that has ACID properties, such as SQLite. Far fewer I/O operations are required for small updates. It's not the 1980s any more. I agree with this approach. However, the OP specifically asked about "how to update stat

Re: How to safely maintain a status file

2012-07-12 Thread Laszlo Nagy
You are contradicting yourself. Either the OS is providing a fully atomic rename or it doesn't. All POSIX compatible OS provide an atomic rename functionality that renames the file atomically or fails without loosing the target side. On POSIX OS it doesn't matter if the target exists. This is no

Re: How to safely maintain a status file

2012-07-08 Thread Laszlo Nagy
On Sun, 8 Jul 2012 21:29:41 +1000, Richard Baron Penman declaimed the following in gmane.comp.python.general: and then on startup read from tmp_file if status_file does not exist. But this seems awkward. It also violates your requirement -- since the "crash" could take place with a par

Re: 2 + 2 = 5

2012-07-05 Thread Laszlo Nagy
On 2012-07-04 21:37, Paul Rubin wrote: I just came across this (https://gist.github.com/1208215): import sys import ctypes pyint_p = ctypes.POINTER(ctypes.c_byte*sys.getsizeof(5)) five = ctypes.cast(id(5), pyint_p) print(2 + 2 == 5) # False five.contents[five.conten

documentation for asyncmongo?

2012-04-07 Thread Laszlo Nagy
Is there any kind of API documentation for asyncmongo? On GITHub they say "asyncmongo syntax strives to be similar to pymongo .". However, many basic things do not work or they are not similar. http://api.mongodb.org/python/2.1

Re: Async IO Server with Blocking DB

2012-04-06 Thread Laszlo Nagy
There is asyncmongo! http://pypi.python.org/pypi/asyncmongo/0.1.3 Although I have never tried it. It has support for async I/O for mongodb and tornadoweb. Here is a bit old article about it: http://www.dunnington.net/entry/asynchronous-mongodb-in-tornado-with-asyncmongo I have a related ques

Re: urllib.urlretrieve never returns???

2012-03-21 Thread Laszlo Nagy
On 2012-03-20 22:26, Prasad, Ramit wrote: I just looked at your source file on ActiveState and noticed that you do not import traceback. That is why you are getting the AttributeError. Now you should be getting a much better error once you import it:) Nope. That would result in a NameError. After

Re: urllib.urlretrieve never returns??? [SOLVED] - workaround

2012-03-20 Thread Laszlo Nagy
I'll be experimenting with pyCurl now. By replacing the GetThumbnail method with this brainless example, taken from the pyCurl demo: def GetThumbnail(self,imgurl): class Test: def __init__(self): self.contents = '' def body_callback(self,

Re: urllib.urlretrieve never returns???

2012-03-20 Thread Laszlo Nagy
2012.03.20. 8:08 keltezéssel, Laszlo Nagy írta: Here you can find the example program and the original post. http://code.activestate.com/lists/python-list/617894/ I gather you are running urlretrieve in a separate thread, inside a GUI? Yes. I have learned that whenever I have inexplicable

Re: urllib.urlretrieve never returns???

2012-03-20 Thread Laszlo Nagy
Here you can find the example program and the original post. http://code.activestate.com/lists/python-list/617894/ I gather you are running urlretrieve in a separate thread, inside a GUI? Yes. I have learned that whenever I have inexplicable behaviour in a function, I should check my assumpt

Re: urllib.urlretrieve never returns???

2012-03-19 Thread Laszlo Nagy
The pythonw.exe may not have the rights to access network resources. Have you set a default timeout for sockets? import socket socket.setdefaulttimeout(10) # 10 seconds I have added pythonw.exe to allowed exceptions. Disabled firewall completely. Set socket timeout to 10 seconds. Still nothing.

Re: urllib.urlretrieve never returns???

2012-03-19 Thread Laszlo Nagy
On 2012-03-17 19:18, Christian Heimes wrote: Am 17.03.2012 15:13, schrieb Laszlo Nagy: See attached example code. I have a program that calls exactly the same code, and here is the strange thing about it: * Program is started as "start.py", e.g. with an open console. In this

Re: urllib.urlretrieve never returns???

2012-03-17 Thread Laszlo Nagy
2012.03.17. 17:34 keltezéssel, Chris Angelico wrote 2012/3/18 Laszlo Nagy: In the later case, "log.txt" only contains "#1" and nothing else. If I look at pythonw.exe from task manager, then its shows +1 thread every time I click the button, and "#1" is appen

  1   2   3   4   5   >