5 ms·
I wish you could compile scons with pypi.
by tbrock 12y ago
I wish you could compile scons with pypi.
- ginko 12y agoWhat OS are you using scons on? I found that scons is way slower on Windows than it is on Linux.
- mikeash 12y agoA nitpick I only bring up because the similarity sometimes confuses me: you mean pypy, which is python-on-python done fast. Pypi is the Python Package Index, a separate thing.
- tbrock 12y agoYes sorry iPhone autocorrect, I'm talking about pypy
- mattip 12y agoYou mean "I wish you could run scons with PyPY". It looks to me like scons does contents = open(file).read() where they should be doing with open(file) as fid: contents = fid.read()
- anon4 12y agoWhat is the difference between the two?
- fijal 12y agoIt's documented in PyPy differences, but generally open('x').read() does not guarantee that a file is closed. In CPython it's not a problem due to refcounting, but in pypy, the file might be closed at some later stage. There is additionally a silly low number of open file descriptors, which limits how many files you can have open at once.
- masklinn 12y ago> In CPython it's not a problem due to refcounting, but in pypy, the file might be closed at some later stage. Technically the guarantee in CPython is "soft" so it can be a problem, just rarely is: if the file gets referenced from an object accessible from a cycle the file won't be released (and closed) until the cycle-breaking GC is triggered.
- objectified 12y agoThe latter uses a Python context manager to open the file, the former doesn't. By using the open() context manager like this, you don't need to worry about closing the file yourself, since the context manager takes care of it. The code that runs inside the 'with' block gets yielded inside the context manager. The former version of the code does not store a reference to the file handle, thus cannot close the file handle. Of course you can close file handles without using a context manager too: f = open('foo.txt') contents = f.read() f.close() But I'd prefer this way: with open('foo.txt') as f: contents = f.read() Context managers can of course be used for all kinds of things. For more information, see https://docs.python.org/2/library/contextlib.html https://docs.python.org/2/library/contextlib.html
- codefisher 12y agoThe equivalent code with out the context manager is actually this: f = open('foo.txt') try: contents = f.read() finally: f.close() So yes, extra reason to prefer the context manager.