ANN: psutil 1.0.0 released
Hi there folks, I'm pleased to announce the 1.0.0 release of psutil: http://code.google.com/p/psutil/ === About === psutil is a module providing an interface for retrieving information on all running processes and system utilization (CPU, memory, disks, network, users) in a portable way by using Python. It currently supports Linux, Windows, OSX, FreeBSD and Sun Solaris, both 32-bit and 64-bit, with Python versions from 2.4 to 3.3 by using a single code base. === New features === This new release finally includes support for Sun Solaris systems! I wish to thank Justin Venus who first wrote a prototype in Cython which I then converted in C (full story here: https://code.google.com/p/psutil/issues/detail?id=18). Complete list of bugfixes and enhancements is here: https://psutil.googlecode.com/hg/HISTORY === Compatitility notes === There's a couple of things you may want to know in terms of backward compatibility: * Process.get_connections() 'status' field is no longer a string but a constant object (psutil.CONN_*) * Process.get_connections() 'local_address' and 'remote_address' fields have been renamed to 'laddr' and 'raddr' * psutil.network_io_counters() has been renamed to psutil.net_io_counters() There are still aliases for the old names. They will issue a DeprecationWarning though. === Links === * Home page: http://code.google.com/p/psutil * Source tarball: http://psutil.googlecode.com/files/psutil-1.0.0.tar.gz * API Reference: http://code.google.com/p/psutil/wiki/Documentation Please try out this new release and let me know if you experience any problem by filing issues on the bug tracker. Thanks in advance and hooray for the new Solaris support! ;-) All the best, --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/ -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: psutil 1.0.0 released
> Congratulations on the 1.0.0 release! Thanks a lot. =) > Btw. any change you can put up a prebuilt installer for a 64-bit built > with Python 3.3? You have one for Python 3.2 > (http://code.google.com/p/psutil/downloads/list), but the version for Python > 3.3 is not there. Unfortunately I'm having troubles with Visual Studio 64-bit I still haven't managed to fix. Hope I will get around that soon. --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/ -- http://mail.python.org/mailman/listinfo/python-list
ANN: psutil 5.3.0 with full unicode support is out
Hello all, I'm glad to announce the release of psutil 5.3.0: https://github.com/giampaolo/psutil A blogpost describing the main changes is available here: http://grodola.blogspot.com/2017/09/psutil-530-with-full-unicode-support-is.html About = psutil (process and system utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) in Python. It is useful mainly for system monitoring, profiling and limiting process resources and management of running processes. It implements many functionalities offered by command line tools such as: ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap. It currently supports Linux, Windows, OSX, Sun Solaris, FreeBSD, OpenBSD and NetBSD, both 32-bit and 64-bit architectures, with Python versions from 2.6 to 3.5 (users of Python 2.4 and 2.5 may use 2.1.3 version). PyPy is also known to work. What's new == **Enhancements** - #802: disk_io_counters() and net_io_counters() numbers no longer wrap (restart from 0). Introduced a new "nowrap" argument. - #928: psutil.net_connections() and psutil.Process.connections() "laddr" and "raddr" are now named tuples. - #1015: swap_memory() now relies on /proc/meminfo instead of sysinfo() syscall so that it can be used in conjunction with PROCFS_PATH in order to retrieve memory info about Linux containers such as Docker and Heroku. - #1022: psutil.users() provides a new "pid" field. - #1025: process_iter() accepts two new parameters in order to invoke Process.as_dict(): "attrs" and "ad_value". With this you can iterate over all processes in one shot without needing to catch NoSuchProcess and do list/dict comprehensions. - #1040: implemented full unicode support. - #1051: disk_usage() on Python 3 is now able to accept bytes. - #1058: test suite now enables all warnings by default. - #1060: source distribution is dynamically generated so that it only includes relevant files. - #1079: [FreeBSD] net_connections()'s fd number is now being set for real (instead of -1). (patch by Gleb Smirnoff) - #1091: [SunOS] implemented Process.environ(). (patch by Oleksii Shevchuk) **Bug fixes** - #989: [Windows] boot_time() may return a negative value. - #1007: [Windows] boot_time() can have a 1 sec fluctuation between calls; the value of the first call is now cached so that boot_time() always returns the same value if fluctuation is <= 1 second. - #1013: [FreeBSD] psutil.net_connections() may return incorrect PID. (patch by Gleb Smirnoff) - #1014: [Linux] Process class can mask legitimate ENOENT exceptions as NoSuchProcess. - #1016: disk_io_counters() raises RuntimeError on a system with no disks. - #1017: net_io_counters() raises RuntimeError on a system with no network cards installed. - #1021: [Linux] open_files() may erroneously raise NoSuchProcess instead of skipping a file which gets deleted while open files are retrieved. - #1029: [OSX, FreeBSD] Process.connections('unix') on Python 3 doesn't properly handle unicode paths and may raise UnicodeDecodeError. - #1033: [OSX, FreeBSD] memory leak for net_connections() and Process.connections() when retrieving UNIX sockets (kind='unix'). - #1040: fixed many unicode related issues such as UnicodeDecodeError on Python 3 + UNIX and invalid encoded data on Windows. - #1042: [FreeBSD] psutil won't compile on FreeBSD 12. - #1044: [OSX] different Process methods incorrectly raise AccessDenied for zombie processes. - #1046: [Windows] disk_partitions() on Windows overrides user's SetErrorMode. - #1047: [Windows] Process username(): memory leak in case exception is thrown. - #1048: [Windows] users()'s host field report an invalid IP address. - #1050: [Windows] Process.memory_maps memory() leaks memory. - #1055: cpu_count() is no longer cached; this is useful on systems such as Linux where CPUs can be disabled at runtime. This also reflects on Process.cpu_percent() which no longer uses the cache. - #1058: fixed Python warnings. - #1062: disk_io_counters() and net_io_counters() raise TypeError if no disks or NICs are installed on the system. - #1063: [NetBSD] net_connections() may list incorrect sockets. - #1064: [NetBSD] swap_memory() may segfault in case of error. - #1065: [OpenBSD] Process.cmdline() may raise SystemError. - #1067: [NetBSD] Process.cmdline() leaks memory if process has terminated. - #1069: [FreeBSD] Process.cpu_num() may return 255 for certain kernel processes. - #1071: [Linux] cpu_freq() may raise IOError on old RedHat distros. - #1074: [FreeBSD] sensors_battery() raises OSError in case of no battery. - #1075: [Windows] net_if_addrs(): inet_ntop() return value is not checked. - #1077: [SunOS] net_if_addrs() shows garbage addresses on SunOS 5.10. (patch by Oleksii Shevchuk) - #1077: [SunOS] net_connections() does not work on SunOS 5.10. (patch by Oleksii Shevchuk) - #1079: [FreeBSD] net_conne
Re: ANN: psutil 5.3.0 with full unicode support is out
Hello Eryk, it is true that the most correct way to represent strings in Python 2 is by dealing with Unicode but it is also true that the most common scenario in both the stdlib and most third party libs is to return and deal with str (bytes) instead, so this is why I decided to do the same in psutil. Other than _winreg I can't recall other APIs returning Unicode by default unless explicitly asked (e.g os.getcwdu() or os.listdir(u'.')) and I didn't want to duplicate psutil APIs in the same fashion. It must be noted that many stdlib APIs in Python 2 are "broken" when it comes to Unicode, see: http://bugs.python.org/issue18695 ...so the most convenient and definitive "fix" to correctly handle strings in Python is switching to Python 3. With that said, in psutil on Python 2 you are still supposed to be able retrieve the "correct" string by using the "replace" error handler: >>> unicode(proc.exe(), sys.getdefaultencoding(), errors="replace") This is an example which filters processes with a funky name which works with both Python 2 and 3: import psutil, sys PY3 = sys.version_info[0] == 2 LOOKFOR = u"ƒőő.exe" for proc in psutil.process_iter(attrs=['name']): name = proc.info['name'] if not PY3: name = unicode(name, sys.getdefaultencoding(), errors="replace") if LOOKFOR == name: print("process %s found" % p) This is IMO the best compromise for a lib which aims to work on both Python 2 and 3. It's either that or returning Unicode all over the place in Python 2, but that's something I considered and rejected because most of the times the string is not supposed to have funky characters, so "practicality beats purity" in this case. On Sun, Sep 3, 2017 at 11:38 PM, eryk sun wrote: > On Sun, Sep 3, 2017 at 9:58 AM, Giampaolo Rodola' > wrote: > > > > - #1040: all strings are encoded by using OS fs encoding. > > - #1040: the following Windows APIs on Python 2 now return a string > instead > > of > > unicode: > > - Process.memory_maps().path > > - WindowsService.bin_path() > > - WindowsService.description() > > - WindowsService.display_name() > > - WindowsService.username() > > This seems wrong. User names, file paths, registry strings, etc are > all Unicode in Windows. One cannot in general encode them as the > legacy (as in it really should be avoided) 'mbcs' encoding, i.e. ANSI. > Using the 'replace' handler will make a mess with best-fit > replacements and question marks. For example, _winreg in Python 2 has > to return unicode strings and always has, which should be the > precedent for psutil. Python 2 code that supports Windows has to be > able to handle this. > -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Re: ANN: psutil 5.3.0 with full unicode support is out
Mmm thanks for pointing this out. I don't have a Windows machine to test this against right now but it seems you're right and there's something wrong in my example (which is what I recommend in the official doc BTW, so it needs to be fixed). That aside, do you think the rest of my reasoning makes sense? I mean returning str all the time and provide a strategy to convert the string to unicode in Python 2? On Mon, Sep 4, 2017 at 2:54 PM, eryk sun wrote: > On Sun, Sep 3, 2017 at 11:09 PM, Giampaolo Rodola' > wrote: > > > > This is an example which filters processes with a funky name which works > > with both Python 2 > > and 3: > > > > import psutil, sys > > > > PY3 = sys.version_info[0] == 2 > > LOOKFOR = u"ƒőő.exe" > > for proc in psutil.process_iter(attrs=['name']): > > name = proc.info['name'] > > if not PY3: > > name = unicode(name, sys.getdefaultencoding(), > errors="replace") > > if LOOKFOR == name: > > print("process %s found" % p) > > > > This is IMO the best compromise for a lib which aims to work on both > Python > > 2 and 3. It's either that or returning Unicode all over the place in > Python > > 2, but that's something I considered and rejected because most of the > times > > the string is not supposed to have funky characters, so "practicality > beats > > purity" in this case. > > The encoded name for ANSI codepage 1252 is "\x83oo.exe". Python 2's > default encoding is ASCII, so the decoded result is u'\ufffdoo.exe'. > Even if it should be the filesystem encoding ('mbcs'), the result is > u"ƒoo.exe". Neither equals u"ƒőő.exe". > > Instead, shouldn't it encode LOOKFOR as "mbcs" with errors="replace" > before comparing it to proc.info['name']? > -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
ANN: released psutil 5.0.0, introducing a 2x speedup for process methods
Hello all, I'm glad to announce the release of psutil 5.0.0: https://github.com/giampaolo/psutil This release introduces important speedups making psutil from 2x to 6x faster depending on what platform you're on. A full blog post can be found here: http://grodola.blogspot.com/2016/11/psutil-500-is-around-twice-as-fast.html About = psutil (process and system utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) in Python. It is useful mainly for system monitoring, profiling and limiting process resources and management of running processes. It implements many functionalities offered by command line tools such as: ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap. It currently supports Linux, Windows, OSX, Sun Solaris, FreeBSD, OpenBSD and NetBSD, both 32-bit and 64-bit architectures, with Python versions from 2.6 to 3.5 (users of Python 2.4 and 2.5 may use 2.1.3 version). PyPy is also known to work. What's new == *2016-11-06* **Enhncements** - #799: new Process.oneshot() context manager making Process methods around +2x faster in general and from +2x to +6x faster on Windows. - #943: better error message in case of version conflict on import. **Bug fixes** - #932: [NetBSD] net_connections() and Process.connections() may fail without raising an exception. - #933: [Windows] memory leak in cpu_stats() and WindowsService.description(). Links = - Home page: https://github.com/giampaolo/psutil - Download: https://pypi.python.org/pypi/psutil - Documentation: http://pythonhosted.org/psutil - What's new: https://github.com/giampaolo/psutil/blob/master/HISTORY.rst -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
ANN: psutil 4.2.0 with Windows service support is out
Full blog post: http://grodola.blogspot.com/2016/05/psutil-420-windows-services-and-python.html -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
ANN: psutil 4.2.0 with Windows service support is out
Full blog post: http://grodola.blogspot.com/2016/05/psutil-420-windows-services-and-python.html -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Re: proposal: bring nonlocal to py2.x
On Mon, Jan 13, 2014 at 3:47 PM, Neal Becker wrote: > py3 includes a fairly compelling feature: nonlocal keywork > But backward compatibility is lost. It would be very helpful > if this was available on py2.x. > > -- > https://mail.python.org/mailman/listinfo/python-list > It's not gonna happens as per PEP-404: http://www.python.org/dev/peps/pep-0404/ -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
ANN: released psutil 3.3.0 with OpenBSD support
Full story here: http://grodola.blogspot.com/2015/11/openbsd-support-for-psutil.html -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
ANN: psutil 4.0.0 released - how to get "real" process memory and environ in Python
Full blog post: http://grodola.blogspot.com/2016/02/psutil-4-real-process-memory-and-environ.html -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Python 2.x and 3.x use survey, 2014 edition
On Wed, Dec 10, 2014 at 5:59 PM, Bruno Cauet wrote: > Hi all, > Last year a survey was conducted on python 2 and 3 usage. > Here is the 2014 edition, slightly updated (from 9 to 11 questions). > It should not take you more than 1 minute to fill. I would be pleased if > you took that time. > > Here's the url: http://goo.gl/forms/tDTcm8UzB3 > I'll publish the results around the end of the year. > > Last year results: https://wiki.python.org/moin/2.x-vs-3.x-survey > > Thank you > Bruno > > ___ > Python-Dev mailing list > python-...@python.org > https://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > https://mail.python.org/mailman/options/python-dev/g.rodola%40gmail.com > I still think the only *real* obstacle remains the lack of important packages such as twisted, gevent and pika which haven't been ported yet. With those ones ported switching to Python 3 *right now* is not only possible and relatively easy, but also convenient. -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 2.x and 3.x use survey, 2014 edition
On Thu, Dec 11, 2014 at 10:32 PM, Ben Finney wrote: > > "Giampaolo Rodola'" writes: > > > I still think the only *real* obstacle remains the lack of important > > packages such as twisted, gevent and pika which haven't been ported > > yet. > > What disqualifies other obstacles from being “*real* obstacles”? How do > you determine that? > > > With those ones ported switching to Python 3 *right now* is not only > > possible and relatively easy, but also convenient. > > If my program relies on an obscure library ‘foo’, and that library is > not ported to Python 3, switching to Python 3 is not feasible, and > certainly not convenient — regardless of the status of “important > packages such as twisted, gevent, and pika”. > > So your assertion here is plainly false. > > What is it you're actually wanting to say? What I'm saying is that for a very long time a considerable number of libraries haven't been ported to python 3 and that lasted for years, say until Python 3.3, or until Django started supporting Python 3, which happened less than a year ago. Names such as Twisted, gevent, eventlet, python-daemon and paramiko means that literally hundreds of thousands of users cannot even think about migrating *right now*: they're just stuck. My perception is that for way too long Python 3 was kind of ignored by some of the most important library vendors and it (partially) still is, and that's what is affecting Python 3 adoption the most. Try to take a look at how many missing dependencies a project such as OpenStack still has: http://stackoverflow.com/questions/20075574/finding-which-packages-support-python-3-x-vs-2-7-x/22113627#22113627. OpenStack is probably a bad example 'cause it's *huge*, but when the missing deps have hundreds of thousands of user (see https://python3wos.appspot.com/) it is very easy to hit one of those and remain stuck even if your project is a lot smaller. I personally tried to migrate 2 medium-sized (> 10.000 LOC) projects at work for 2 different companies and what I ended up doing was modernizing the code so that both 2.7 and 3.3+ interpreters could execute it and tests didn't raise any "python-related error" (SyntaxError, TypeError, UnicodeError or whatever), but I punctually hit the wall of 1, 2 or 3 missing dependencies. So basically both of these 2 projects are "python 3 ready" but since the library ecosystem is not I just "wait" (it's been a year now). -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
ANN: psutil 2.2.0 released
Hello all, I'm glad to announce the release of psutil 2.2.0. In this new release I decided to drop support for Python 2.4 and 2.5 for good. Whoever is still on Python 2.4 and 2.5 can use old 2.1.3 version: https://pypi.python.org/pypi?name=psutil&version=2.1.3&:action=files Main features and bugfixes == - FreeBSD has now support for process CPU affinity - new pstree.py and pidof.py example scripts - C extension version mismatch in case the user messed up with psutil installation or with sys.path is now detected at import time - [Linux] a lot of file descriptors were left open - [Windows] use proper encoding for psutil.Process.username() and psutil.users(). - [Solaris] fixed a high-priority bug which crashed psutil on import. The list of all enhancements and bugfixes is here: https://github.com/giampaolo/psutil/blob/master/HISTORY.rst#220---2015-01-06 Links = * Home page: https://github.com/giampaolo/psutil * Downloads: https://pypi.python.org/pypi?:action=display&name=psutil#downloads * Documentation: http://pythonhosted.org/psutil/ Please try out this new release and let me know if you experience any problem by filing issues on the bug tracker. All the best, -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
ANN: psutil 2.0.0 released
Hi there folks, I'm pleased to announce the 2.0.0 release of psutil: http://code.google.com/p/psutil/ === About === psutil (python system and process utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) in Python. It is useful mainly for system monitoring, profiling and limiting process resources and management of running processes. It implements many functionalities offered by command line tools such as: ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap. It currently supports Linux, Windows, OSX, FreeBSD and Sun Solaris, both 32-bit and 64-bit architectures, with Python versions from 2.4 to 3.4. Pypi is also known to work. === What changed === A lot. I tried to address all the changes in this blog post: http://grodola.blogspot.com/2014/03/psutil-20.html === Links === * Home page: http://code.google.com/p/psutil * Downloads: https://pypi.python.org/pypi?:action=display&name=psutil#downloads * Documentation: http://psutil.readthedocs.org/ Please try out this new release and let me know if you experience any problem by filing issues on the bug tracker. Best, -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Re: which async framework?
On Tue, Mar 11, 2014 at 11:17 AM, Sturla Molden wrote: > Chris Withers wrote: > > Hi All, > > > > I see python now has a plethora of async frameworks and I need to try > > and pick one to use from: > > > > - asyncio/tulip > > - tornado > > - twisted > > Looking at Tornado's examples on the web I find this: > > tornado.ioloop.IOLoop.instance().start() > > This single line of code says more than thousand words. But it boils down > to: > > (1) This was written by some Java guys. > (2) Someone used Python to write Java. > > And that's all I need to know about Tornado. Tornado is actually very Pythonic and has a very well written and modern code base. I think "tornado.ioloop.IOLoop.instance().start()" is the way it is in order to let you use multiple IO loops in different threads but I can't think of other places where such an idiom is used. What one might find a little Java-esque at a first glance is Twisted, because of zope.interface and the camelCase notation, but definitively not Tornado. -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] [RELEASED] Python 3.4.0
The what's new looks truly amazing, with pathlib and asyncio being my favourite additions. Thanks for all the hard work. On Mon, Mar 17, 2014 at 5:57 PM, Ryan Gonzalez wrote: > YES!!! +1 to the authors of the statistics and pathlib modules. > > > On Mon, Mar 17, 2014 at 1:29 AM, Larry Hastings wrote: > >> >> On behalf of the Python development team, I'm thrilled to announce >> the official release of Python 3.4. >> >> >> Python 3.4 includes a range of improvements of the 3.x series, including >> hundreds of small improvements and bug fixes. Major new features and >> changes in the 3.4 release series include: >> >> * PEP 428, a "pathlib" module providing object-oriented filesystem paths >> * PEP 435, a standardized "enum" module >> * PEP 436, a build enhancement that will help generate introspection >>information for builtins >> * PEP 442, improved semantics for object finalization >> * PEP 443, adding single-dispatch generic functions to the standard >> library >> * PEP 445, a new C API for implementing custom memory allocators >> * PEP 446, changing file descriptors to not be inherited by default >>in subprocesses >> * PEP 450, a new "statistics" module >> * PEP 451, standardizing module metadata for Python's module import system >> * PEP 453, a bundled installer for the *pip* package manager >> * PEP 454, a new "tracemalloc" module for tracing Python memory >> allocations >> * PEP 456, a new hash algorithm for Python strings and binary data >> * PEP 3154, a new and improved protocol for pickled objects >> * PEP 3156, a new "asyncio" module, a new framework for asynchronous I/O >> >> >> To download Python 3.4.0 visit: >> >> http://www.python.org/download/releases/3.4.0/ >> >> >> This is a production release. Please report any issues you notice to: >> >> http://bugs.python.org/ >> >> >> Enjoy! >> >> >> -- >> Larry Hastings, Release Manager >> larry at hastings.org >> (on behalf of the entire python-dev team and 3.4's contributors) >> ___ >> Python-Dev mailing list >> python-...@python.org >> https://mail.python.org/mailman/listinfo/python-dev >> Unsubscribe: https://mail.python.org/mailman/options/python-dev/ >> rymg19%40gmail.com >> > > > > -- > Ryan > If anybody ever asks me why I prefer C++ to C, my answer will be simple: > "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was > nul-terminated." > > > -- > https://mail.python.org/mailman/listinfo/python-list > > -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Upload Windows binaries on pypi from Linux
I have a Python extension module (psutil) written in C which I compile for different Python versions (from 2.4 to 3.3) and want to upload them on pypi. The Windows machine is not connected to internet so after I generate the Windows binaries (via setup.py bdist_wininst) I move the .exe files from Windows to Linux. From there I want to upload all the *.exe files on pypi. Apparently I can automatically do this only from Windows via "setup.py upload bdist_wininst" but as I said I have no internet connection on that box. Is there a way to tell setup.py to upload those *.exe file on pypi from Linux or some tool which can do that via HTTP POST or something? Thanks in advance, --- Giampaolo https://code.google.com/p/pyftpdlib/ https://code.google.com/p/psutil/ https://code.google.com/p/pysendfile/ -- https://mail.python.org/mailman/listinfo/python-list
ANN: psutil 1.1.0 released
Hi there folks, I'm pleased to announce the 1.1.0 release of psutil: http://code.google.com/p/psutil/ === About === psutil is a module providing an interface for retrieving information on all running processes and system utilization (CPU, memory, disks, network, users) in a portable way by using Python, implementing many functionalities offered by command line tools such as ps, top, free, netstat, lsof and others. It supports Linux, Windows, OSX, FreeBSD and Solaris with Python versions from 2.4 to 3.4. === New features === The main addition included in this new release is the possibility to set process resource limits on Linux (see "man prlimit"). This functionality is similar to what you can already do with stdlib resource module (http://docs.python.org/2/library/resource.html) but it is extended to all processes. For example, you might limit the number of files which may be opened by a process: >>> p = psutil.Process(pid) >>> p.set_rlimit(psutil.RLIMIT_NOFILE, (128, 128)) >>> files = [] >>> for x in range(200): ... files.append(open('/tmp/foo')) ... Traceback (most recent call last): File "", line 2, in IOError: [Errno 24] Too many open files: '/tmp/foo' ...or the maximum size of files that the process may create: >>> p.set_rlimit(psutil.RLIMIT_FSIZE, (1024, 1024)) >>> f = open('/tmp/foo', 'w') >>> f.write('x' * 1024) >>> f.flush() >>> f.write('x') >>> f.flush() Traceback (most recent call last): File "", line 1, in IOError: [Errno 27] File too large >>> === Main bugfixes === * Process.as_dict() return value couldn't be serialized to JSON. * [Windows] fixed a pretty serious memory leak in Process.get_memory_info(). * [Windows] Process get_children() and "name" property are an order of magnitude faster. === Other changes === * STATUS_* and CONN_* constants (returned by Process' status() and get_connections() methods respectively) have been turned from constant objects to plain Python strings. * source and Windows binary files are now hosted on PyPi Complete list of bugfixes and enhancements is here: https://psutil.googlecode.com/hg/HISTORY === Links === * Home page: http://code.google.com/p/psutil * Downloads: https://pypi.python.org/pypi?:action=display&name=psutil#downloads * API Reference: http://code.google.com/p/psutil/wiki/Documentation Please try out this new release and let me know if you experience any problem by filing issues on the bug tracker. All the best, --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ http://code.google.com/p/pysendfile/ -- https://mail.python.org/mailman/listinfo/python-list
Re: [ANN] ftputil 3.0a1 released
Glad to hear there's someone else other than me who still cares about the almost forgotten FTP protocol! =) --- Giampaolo https://code.google.com/p/pyftpdlib/ https://code.google.com/p/psutil/ https://code.google.com/p/pysendfile/ On Sun, Sep 29, 2013 at 8:00 PM, Stefan Schwarzer wrote: > ftputil 3.0a1 is now available from > http://ftputil.sschwarzer.net/download . > > Changes since version 2.8 > - > > Note: This version of ftputil is _not_ backward-compatible > with earlier versions.See the links below for information > on adapting existing client code. > > - This version adds Python 3 compatibility! :-) > > The same source is used for Python 2.x and Python 3.x. > > I had to change the API to find a good compromise for > both Python versions. > > - ftputil now requires at least Python 2.6. > > - Remote file-like objects use the same semantics as Python's > `io` module. (This is the same as for the built-in `open` > function in Python 3.) > > - `ftputil.ftp_error` was renamed to `ftputil.error`. > > - For custom parsers, import `ftputil.parser` instead of > `ftputil.stat`. > > For more information please read > http://ftputil.sschwarzer.net/trac/wiki/WhatsNewInFtputil3.0 > http://ftputil.sschwarzer.net/trac/wiki/PreReleaseDocumentation > > What is ftputil? > > > ftputil is a high-level FTP client library for the Python programming > language. ftputil implements a virtual file system for accessing FTP > servers, that is, it can generate file-like objects for remote files. > The library supports many functions similar to those in the os, > os.path and shutil modules. ftputil has convenience functions for > conditional uploads and downloads, and handles FTP clients and servers > in different timezones. > > License > --- > > ftputil is Open Source software, released under the revised BSD > license (see http://opensource.org/licenses/BSD-3-Clause ). > > Stefan > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
ANN: psutil 3.0.0 is out
Hi there folks, I'm pleased to announce release 3.0.0 release of psutil: http://grodola.blogspot.com/2015/06/psutil-30.html === About === psutil (python system and process utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) in Python. It is useful mainly for system monitoring, profiling and limiting process resources and management of running processes. It implements many functionalities offered by command line tools such as: ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap. It currently supports Linux, Windows, OSX, FreeBSD and Sun Solaris, both 32-bit and 64-bit architectures, with Python versions from 2.4 to 3.4. Pypi is also known to work. What changed === See detailed blog post: http://grodola.blogspot.com/2015/06/psutil-30.html Links * Home page: https://github.com/giampaolo/psutil * Downloads: https://pypi.python.org/pypi?:action=display&name=psutil#downloads * Documentation: http://pythonhosted.org/psutil/ -- Giampaolo - http://grodola.blogspot.com -- https://mail.python.org/mailman/listinfo/python-list
Re: python process accounting
2013/4/30 Rita : > Hi, > > I was wondering if it possible to write a python wrapper which will account > my processes. I would like to account for all the children processes (fork) > by looking at their /proc/ info. Such as memory, io, open files, stats. > > So, instead of me running "/bin/sleep 10", i would like to run it as > "pywrap.py /bin/sleep 10" and it will do an exec /bin/sleep 10 and do a > periodic snapshot for whats in /proc//stats. > > > > > -- > --- Get your facts first, then you can distort them as you please.-- > > -- > http://mail.python.org/mailman/listinfo/python-list > Not sure what you're talking about expect for the process management part in which case it seems you're looking for psutil: https://code.google.com/p/psutil/#Process_management In detail, if you want to work with process children: >>> import psutil, os >>> thisproc = psutil.Process(os.getpid()) >>> for child in thisproc.get_children(): ... print child.name ... print child.get_memory_info() ... print child.get_open_files() ... --- Giampaolo https://code.google.com/p/pyftpdlib/ https://code.google.com/p/psutil/ https://code.google.com/p/pysendfile/ -- http://mail.python.org/mailman/listinfo/python-list
Integrating a GUI with an asyncore-based server
Hi there. Just for the heck of it I'd like to write a simple front-end for an asyncore-based server I wrote by using Tkinter. I wrote a simple graphical interface consisting of two buttons: "Start server" and "Stop server". The first button should start the asyncore main loop while the second should obviously stop it. Actually I can't find a valid solution for doing such a stuff since this is the first time I'm using a GUI toolkit. Which is the best approach to use in such case? Could someone point me in the right direction? -- http://mail.python.org/mailman/listinfo/python-list
Integrating a GUI with an asyncore-based server
Hi there. Just for the heck of it I'd like to write a simple front-end for an asyncore-based server I wrote by using Tkinter. I wrote a simple graphical interface consisting of two buttons: "Start server" and "Stop server". The first button should start the asyncore main loop while the second should obviously stop it. Actually I can't find a valid solution for doing such a stuff since this is the first time I'm using a GUI toolkit. Which is the best approach to use in such case? Could someone point me in the right direction? -- http://mail.python.org/mailman/listinfo/python-list
Adding idle timeout capabilities to asyncore
Hi there. We're talking about an asyncore-based server. Just for the heck of it I'd like to set a timeout which will disconnects the clients if they're inactive (i.e., no command or data transfer in progress) for a long period of time. I was thinking about putting the timeout value into an attribute: def settimeout(self, secs): self.timeout = time.time() + secs And then have the readable method call time.time() at every loop to check if time has passed or not: def readable(self): if time.time() >= self.timeout: self.send("Timeout") self.close() return 1 My only concern is if it's a good idea calling time.time() so often. Since A LOT of clients could be connected simultaneously, couldn't it be a too much resource-intensive operation? I'd also be curious to know how Twisted implemented this kind of stuff. By calling time.time() at every loop? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Adding idle timeout capabilities to asyncore
On 23 Ott, 17:34, Josiah Carlson <[EMAIL PROTECTED]> wrote: > On 22 Ott, 12:28, Giampaolo Rodola' <[EMAIL PROTECTED]> wrote: > > > > > > > Hi there. > > We're talking about an asyncore-based server. > > Just for the heck of it I'd like to set a timeout which will > > disconnects the clients if they're inactive (i.e., no command or data > > transfer in progress) for a long period of time. > > I was thinking about putting the timeout value into an attribute: > > > def settimeout(self, secs): > > self.timeout = time.time() + secs > > > And then have the readable method call time.time() at every loop to > > check if time has passed or not: > > > def readable(self): > > if time.time() >= self.timeout: > > self.send("Timeout") > > self.close() > > return 1 > > > My only concern is if it's a good idea calling time.time() so often. > > Since A LOT of clients could be connected simultaneously, couldn't it > > be a too much resource-intensive operation? > > I'd also be curious to know how Twisted implemented this kind of > > stuff. > > By calling time.time() at every loop? > > > Thanks in advance. > > Calling time.time() is relatively inexpensive in comparison to pure > Python function calls, but indeed, it could be a bottleneck. > > I don't know what Twisted does, but what I would do is to add two > variables to each instance of the class you want to add timeouts to; > self.timeout and self.lastdata . self.lastdata would hold the time > for the last time you sent or received data on the socket, and > self.timeout would hold the delay between when you last sent/received > data and when it should be closed due to idle timeout. > > Now, since you are smart, you don't need to alter your handle_send() > or handle_receive() methods in your asyncore subclass. Instead, you > rewrite asyncore.poll() to update .lastdata for every socket that is > in either the reader or writer list, which will result in one > time.time() call. Further, to check for timeouts, you only ever need > to check those sockets that are *not* in the readable or writable > lists... > > To be precise, add the following block to your own copy of > asyncore.poll just after the 'for fd in e:' block... > > #handle timeouts > rw = set(r) + set(w) > now = time.time() > for f in (i for i in rw if i in map): > map[f].lastdata = now > for j in (map[i] for i in map if i not in rw): > if j.timeout+j.lastdata > now: > #timeout! > j.handle_close() > > You ARE going to need to initialize .timeout and .lastdata members for > every instance, but that shouldn't be so bad (for a socket that > doesn't time out, I would actually suggest a 1 hour or 1 day timeout). > > - Josiah- Nascondi testo tra virgolette - > > - Mostra testo tra virgolette - A really nice hack. Thank you a lot, Josiah. -- http://mail.python.org/mailman/listinfo/python-list
os.readlink returning value
I was reading os.readlink doc which says: readlink( path) Return a string representing the path to which the symbolic link points. The result may be either an absolute or relative pathname; if it is relative, it may be converted to an absolute pathname using os.path.join(os.path.dirname(path), result). Availability: Macintosh, Unix. ...It's not clear to me when the returning result could be absolute and when it could be relative. Could someone clarify this point? -- http://mail.python.org/mailman/listinfo/python-list
Re: os.readlink returning value
On 2 Nov, 05:30, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Thu, 01 Nov 2007 22:51:14 -0300, Giampaolo Rodola' <[EMAIL PROTECTED]> > escribió: > > > I was reading os.readlink doc which says: > > > readlink( path) > > > Return a string representing the path to which the symbolic link > > points. The result may be either an absolute or relative pathname; if > > it is relative, it may be converted to an absolute pathname using > > os.path.join(os.path.dirname(path), result). Availability: Macintosh, > > Unix. > > > ...It's not clear to me when the returning result could be absolute > > and when it could be relative. > > Could someone clarify this point? > > That depends on how the symlink was created. Assume the current directory > is /usr/home/giampaolo/any/dir> ln -s ../foo/bar > > creates a symbolic link at /usr/home/giampaolo/any/dir/bar pointing to > ../foo/bar (relative to where the link resides). That is, actually > pointing to /usr/home/giampaolo/any/foo/bar (but this absolute path is NOT > stored on the link itself - only ../foo/bar) > > Now, a program whose current directory is /usr/home/giampaolo executes > this: > readlink("any/dir/bar") > It will return the string "../foo/bar". One must resolve the .. reference > relative to where the link resides, NOT relative to the current directory. > That is, relative to any/dir. os.path.dirname("any/dir/bar") returns > exactly that. Then, the suggested expression in the docs evaluates to > "any/dir/../foo/bar" - it's not an absolute pathname yet, one should use > abspath() on it. Or instead > os.path.join(os.path.abspath(os.path.dirname(path)), result) > > -- > Gabriel Genellina Thanks for the examplanation. I'd only want to do the same as what ls does in such cases. Imho, os.readlink() should have the same behaviour of ls, isn't it? -- http://mail.python.org/mailman/listinfo/python-list
Re: __file__ vs __FILE__
On 3 Nov, 04:21, klenwell <[EMAIL PROTECTED]> wrote: > I apologize in advance for coming at this from this angle but... > > In PHP you have the __FILE__ constant which gives you the value of the > absolute path of the file you're in (as opposed to the main script > file.) With the function dirname, this makes it easy to get the > parent dir of a particular file from within that file: > > $parent_dir = dirname(__FILE__); > > I'm looking for the best way to accomplish this in Python. This seems > to work: > > parent_dir = os.path.normpath(os.path.join(os.path.abspath(__file__), > '..')) > > Can anyone confirm the reliability of this method or suggest a better > (one-line) method for accomplishing this? > > Thanks, > Tom This is not really 'one-line' since you have to import two modules first, but it looks nicer...: import sys, os print sys.argv[0] # absolute file name print os.path.dirname(sys.argv[0]) # absolute dir name -- http://mail.python.org/mailman/listinfo/python-list
Re: __file__ vs __FILE__
On 3 Nov, 15:46, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Sat, 03 Nov 2007 10:07:10 -0300, Giampaolo Rodola' <[EMAIL PROTECTED]> > escribió: > > > On 3 Nov, 04:21, klenwell <[EMAIL PROTECTED]> wrote: > >> In PHP you have the __FILE__ constant which gives you the value of the > >> absolute path of the file you're in (as opposed to the main script > >> file.) > > This is not really 'one-line' since you have to import two modules > > first, but it looks nicer...: > > > import sys, os > > print sys.argv[0] # absolute file name > > print os.path.dirname(sys.argv[0]) # absolute dir name > > Note that this returns the location of the *main* script, not the current > module, as the OP explicitely asked for. > > -- > Gabriel Genellina Whoops! You're right. -- http://mail.python.org/mailman/listinfo/python-list
ftplib ssl/tls support?
I noticed that poplib, smtplib, httplib, imaplib and probably others include support for ssl connections. Are there future plans for ftplib ssl/tls support? -- http://mail.python.org/mailman/listinfo/python-list
Joining open source python projects
Hi there, I don't know if such a thing has been already discussed, in which case I'm sorry. I was wondering if there's a place for python open source projects that need help. It thought it would be very nice having a place where developers could submit "help requests" for their projects and let the users view them and eventually join them if they want to. Does someone knows if such a service already exist or not? -- http://mail.python.org/mailman/listinfo/python-list
os.path.islink documentation error?
os.path.islink documentation says: "Return True if path refers to a directory entry that is a symbolic link. Always False if symbolic links are not supported." It's not clear to me why it is mentioned the DIRECTORY term. Shouldn't os.path.islink be used to just check if the *path* passed as argument is a symlink? In such case I would change it in: "Return True if path refers to a symbolic link" -- http://mail.python.org/mailman/listinfo/python-list
Is os.lstat available on all platforms?
Hi there. In a code of mine I'd like to use os.lstat whenever possible. My only concern is if it's available on all platforms. It could be safe using always os.lstat instead of: try: os.lstat except AttributeError: os.stat ...? As far as I know where symlinks are not supported os.lstat should be an alias for os.stat but I'm not 100% sure. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is os.lstat available on all platforms?
I'd just want to be sure that even on a strange python implementation I won't ever get an AttributeError exception because os.lstat is not defined. -- http://mail.python.org/mailman/listinfo/python-list
Re: os.path.islink documentation error?
:) You're right... My skimpy English cheated me. -- http://mail.python.org/mailman/listinfo/python-list
Check if a symlink is broken or circular
Hi there, I would like to know if such function would be correct for verifying if a link is broken and/or circular. def isvalidlink(path): assert os.path.islink(path) try: os.stat(path) except os.error: return 1 return 0 -- http://mail.python.org/mailman/listinfo/python-list
Re: Check if a symlink is broken or circular
On 1 Dic, 00:10, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: > > I would like to know if such function would be correct for verifying > > if a link is broken and/or circular. > > > def isvalidlink(path): > > assert os.path.islink(path) > > try: > > os.stat(path) > > except os.error: > > return 1 > > return 0 > > You meant to flip the result values, right? 1 should mean that the > link is value, and 0 that it is not. > > Mostly. If the link is correct, but you don't have permission to stat > the target file, you get 0. OTOH, in that case, you have no way of > finding out whether the link *is* correct. > > Still, you could try to detect the errnos that indicate a problem > with the link itself, and pass all other errors through. > > Regards, > Martin Mmmm... do you mean something like this? Could it be ok? import os, errno def isvalidlink(path): assert os.path.lexists(path) try: os.stat(path) except os.error, err: # broken link # "No such file or directory" if err.errno == errno.ENOENT: return 1 # circular link # "Too many levels of symlinks" elif err.errno == errno.ELOOP: return 2 # something else occurred, # assume it as invalid anyway else: return 3 return 0 -- http://mail.python.org/mailman/listinfo/python-list
Re: Generating API documentation as a textfile
On 3 Dic, 11:26, Samuel <[EMAIL PROTECTED]> wrote: > Does anyone know an easy way to extract the API documentation that is > embedded into a Python file as a text file? > > -Samuel Something like this? print >> open('file.txt', 'w'), dir.__doc__ -- http://mail.python.org/mailman/listinfo/python-list
Re: ftplib.nlst gives error on empty directory
On 7 Dic, 10:42, loial <[EMAIL PROTECTED]> wrote: > Trying to use ftplib.FTP.nlst() method to list the files in > a directory on a FTP server. > > It works fine except when there are no files in the directory. Then it > gives the error > > ftplib.error_perm: 550 No files found. > > How can I handle this cleanly? That's the response which comes straight from the server and that causes ftplib to raise the error_perm exception. imho, the culprit is the server since it shouldn't return that kind of response which clashes with the RFC-959 standard specification. Anyway, to avoid that you could just put your code into a try/except statement: try: files = ftp.nlst() except ftplib.error_perm, resp: if str(resp) == "550 No files found": print "Directory is empty." else: raise ... -- http://mail.python.org/mailman/listinfo/python-list
[search for reviewers] asyncore delayed calls feature
Hi, I post this message here in the hope someone using asyncore could review this. Since the thing I miss mostly in asyncore is a system for calling a function after a certain amount of time, I spent the last 3 days trying to implement this with the hopes that this could be included in asyncore in the the future. The logic consists in calling a certain function (the "scheduler") at every loop to check if it is the proper time to call one or more scheduled functions. Such functions are scheduled by the new delayed_call class which is very similar to the DelayedCall class defined in /twisted/internet/base.py I drew on. It provides a basic API which can be used for setting, resetting and canceling the scheduled functions. For better performance I used an heap queue structure. This way the scheduler() only needs to check the scheduled functions due to expire soonest. diff file and modified asyncore.py can be found here: http://bugs.python.org/issue1641 The following code sample implements an idle-timeout capability using the attached modified asyncore library. --- code snippet --- import asyncore, asynchat, socket class foo(asynchat.async_chat): def __init__(self, conn=None): asynchat.async_chat.__init__(self, conn) self.set_terminator(None) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.connect(('127.0.0.1', 21)) self.scheduled_timeout = self.call_later(120, self.handle_timeout) def collect_incoming_data(self, data): self.scheduled_timeout.reset() # do something with the data... def handle_timeout(self): self.push("500 Connection timed out.\r\n") self.close_when_done() def close(self): if not self.scheduled_timeout.cancelled: self.scheduled_timeout.cancel() asyncore.dispatcher.close(self) foo() asyncore.loop() --- /code snippet --- Today I played a little more with it and I tried to add bandwidth throttling capabilities to the base asynchat.py. The code could be surely improved but it's just an example to show another useful feature which wouldn't be possible to implement without having a "call_later" function under the hood: --- code snippet --- class throttled_async_chat(asynchat.async_chat): # maximum number of bytes to transmit in a second (0 == no limit) read_limit = 100 * 1024 write_limit = 100 * 1024 # smaller the buffers, the less bursty and smoother the throughput ac_in_buffer_size = 2048 ac_out_buffer_size = 2048 def __init__(self, conn=None): asynchat.async_chat.__init__(self, conn) self.read_this_second = 0 self.written_this_second = 0 self.r_timenext = 0 self.w_timenext = 0 self.r_sleep = False self.w_sleep = False self.delayed_r = None self.delayed_w = None def readable(self): return asynchat.async_chat.readable(self) and not self.r_sleep def writable(self): return asynchat.async_chat.writable(self) and not self.w_sleep def recv(self, buffer_size): chunk = asyncore.dispatcher.recv(self, buffer_size) if self.read_limit: self.read_this_second += len(chunk) self.throttle_read() return chunk def send(self, data): num_sent = asyncore.dispatcher.send(self, data) if self.write_limit: self.written_this_second += num_sent self.throttle_write() return num_sent def throttle_read(self): if self.read_this_second >= self.read_limit: self.read_this_second = 0 now = time.time() sleepfor = self.r_timenext - now if sleepfor > 0: # we've passed bandwidth limits self.r_sleep = True def unthrottle(): self.r_sleep = False self.delayed_r = self.call_later((sleepfor * 2), unthrottle) self.r_timenext = now + 1 def throttle_write(self): if self.written_this_second >= self.write_limit: self.written_this_second = 0 now = time.time() sleepfor = self.w_timenext - now if sleepfor > 0: # we've passed bandwidth limits self.w_sleep = True def unthrottle(): self.w_sleep = False self.delayed_w = self.call_later((sleepfor * 2), unthrottle) self.w_timenext = now + 1 def close(self): if self.delayed_r and not self.delayed_r.cancelled: self.delayed_r.cancel() if self.delayed_w and not self.delayed_w.cancelled: self.delayed_w.cancel() asyncore.dispatcher.close(self) --- /code snippet --- I don't know if there's a better way to implement this "call_later" feature. Maybe someone experienced with Twisted could provide a better approach. I would ask someone using asyncore to review this since, IMHO, it would fill a very big
pypi and easy_install
Hi, I noticed tonight that I can't download/install a package of mine hosted on pypi by using easy_install. By running "ez_setup.py pyftpdlib" I get: --- snippet -- options (after parsing config files): no commands known yet options (after parsing command line): option dict for 'aliases' command: {} option dict for 'easy_install' command: {'args': ('command line', ['pyftpdlib']), 'verbose': ('command line', 1)} Searching for pyftpdlib Reading http://pypi.python.org/simple/pyftpdlib/ Reading http://code.google.com/p/pyftpdlib/ No local packages or download links found for pyftpdlib Traceback (most recent call last): File "C:\Documents and Settings\billiejoex\Desktop\ez_setup.py", line 229, in main(sys.argv[1:]) File "C:\Documents and Settings\billiejoex\Desktop\ez_setup.py", line 187, in main main(argv) File "C:\Python25\lib\site-packages\setuptools-0.6c7-py2.5.egg \setuptools\comm and\easy_install.py", line 1670, in main File "C:\Python25\lib\site-packages\setuptools-0.6c7-py2.5.egg \setuptools\comm and\easy_install.py", line 1659, in with_ei_usage File "C:\Python25\lib\site-packages\setuptools-0.6c7-py2.5.egg \setuptools\comm and\easy_install.py", line 1674, in File "C:\Python25\lib\distutils\core.py", line 151, in setup dist.run_commands() File "C:\Python25\lib\distutils\dist.py", line 974, in run_commands self.run_command(cmd) File "C:\Python25\lib\distutils\dist.py", line 994, in run_command cmd_obj.run() File "C:\Python25\lib\site-packages\setuptools-0.6c7-py2.5.egg \setuptools\comm and\easy_install.py", line 211, in run File "C:\Python25\lib\site-packages\setuptools-0.6c7-py2.5.egg \setuptools\comm and\easy_install.py", line 440, in easy_install distutils.errors.DistutilsError: Could not find suitable distribution for Requir ement.parse('pyftpdlib') --- /snippet -- I noticed the following lines: > Searching for pyftpdlib > Reading http://pypi.python.org/simple/pyftpdlib/ > Reading http://code.google.com/p/pyftpdlib/ > No local packages or download links found for pyftpdlib ...which are very weird since, as you can see by looking here: http://pypi.python.org/pypi/pyftpdlib/0.2.0 ...I provided a download url and easy_install SHOULD know where to get the package. Could someone point me in the right direction? -- http://mail.python.org/mailman/listinfo/python-list
Re: pypi and easy_install
On 20 Dic, 03:47, Istvan Albert <[EMAIL PROTECTED]> wrote: > On Dec 19, 9:44 pm, Istvan Albert <[EMAIL PROTECTED]> wrote: > > > On Dec 19, 8:07 pm, "Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote: > > > download_url = 'http://code.google.com/p/pyftpdlib/downloads/list', > > this is from looking at your setup.py here: > > http://pyftpdlib.googlecode.com/svn/trunk/setup.py You're right, the setup.py included in the tarball reports an invalid download url. I fixed the issue in setup.py and used "setup.py register" for uploading the new package on pypi again. As you can see from here: http://pypi.python.org/pypi?name=pyftpdlib&version=0.2.0&:action=display_pkginfo ...now the download url is correct, but the problem still remains. :-\ -- http://mail.python.org/mailman/listinfo/python-list
Re: pypi and easy_install
On 20 Dic, 04:33, "Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote: > On 20 Dic, 03:47, Istvan Albert <[EMAIL PROTECTED]> wrote: > > > On Dec 19, 9:44 pm, Istvan Albert <[EMAIL PROTECTED]> wrote: > > > > On Dec 19, 8:07 pm, "Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote: > > > > download_url = 'http://code.google.com/p/pyftpdlib/downloads/list', > > > this is from looking at your setup.py here: > > >http://pyftpdlib.googlecode.com/svn/trunk/setup.py > > You're right, the setup.py included in the tarball reports an invalid > download url. > I fixed the issue in setup.py and used "setup.py register" for > uploading the new package on pypi again. > As you can see from > here:http://pypi.python.org/pypi?name=pyftpdlib&version=0.2.0&:action=disp... > ...now the download url is correct, but the problem still remains. :-\ Found the culprit. That's because my download URL points to http://pyftpdlib.googlecode.com/files/pyftpdlib_0.2.0.tar.gz, which is not a valid distutils-generated filename. A valid filename for pytftpdblib would be pyftpdlib-0.2.0.tar.gz. -- http://mail.python.org/mailman/listinfo/python-list
Understanding memory leak reports
Hi, I'm in a big trouble since I don't know how to find some memory leaks I just discovered in a program of mine. By putting: import gc gc.set_debug(gc.DEBUG_LEAK) ..at the end of a script which imports a module I wrote it seems I have some memory leaks scattered around. The message printed on screen is the following: gc: collectable gc: collectable gc: collectable gc: collectable gc: collectable gc: collectable gc: collectable Since the main module is very big (more than 2800 lines of code) I do not understand which objects are not garbage collected. Is there a way to have a more detailed message to know which objects are not garbage collected? For example "function foo", "method MyClass.bar", "dict my_dict"... "function 00C70E70" and "tuple 00C09900" are too much generic messages which don't give me an idea about where the leak could be. -- http://mail.python.org/mailman/listinfo/python-list
Re: Understanding memory leak reports
On 21 Dic, 20:10, [EMAIL PROTECTED] wrote: > On Dec 21, 12:44 pm, "Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote: > > > > > > > Hi, > > I'm in a big trouble since I don't know how to find some memory leaks > > I just discovered in a program of mine. > > By putting: > > > import gc > > gc.set_debug(gc.DEBUG_LEAK) > > > ..at the end of a script which imports a module I wrote it seems I > > have some memory leaks scattered around. > > The message printed on screen is the following: > > > gc: collectable > > gc: collectable > > gc: collectable > > gc: collectable > > gc: collectable > > gc: collectable > > gc: collectable > > > Since the main module is very big (more than 2800 lines of code) I do > > not understand which objects are not garbage collected. > > Is there a way to have a more detailed message to know which objects > > are not garbage collected? > > For example "function foo", "method MyClass.bar", "dict my_dict"... > > "function 00C70E70" and "tuple 00C09900" are too much generic messages > > which don't give me an idea about where the leak could be. > > I've never done this before, but here's what I found while Googling: > > Recipe that supposedly gives more > info:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65333 > > Another thread on the same topic that looks quite > detailed:http://www.thescripts.com/forum/thread22097.html > > An article or two on memory leaks in > Python:http://utcc.utoronto.ca/~cks/space/blog/python/DebuggingPythonMemoryL...http://www.nightmare.com/medusa/memory-leaks.html > > I hope they help. > > Mike- Nascondi testo tra virgolette - > > - Mostra testo tra virgolette - Thanks for your search but I haven't actually found a solution yet. I've tried to search into the cookbook. I found other recipes playing with the gc module but it seems that none of them are useful for finding out the names of the objects causing the memory leak. I've tried to play with gc.get_objects() in the hope to find the real names manually but it returns a very large number of objects. If only I could find a way to make gc.get_objects() returning leaking objects only it would be a step forward... Does someone have an idea about how doing such a thing? -- http://mail.python.org/mailman/listinfo/python-list
Re: Understanding memory leak reports
On 22 Dic, 01:27, Ross Ridge <[EMAIL PROTECTED]> wrote: > Giampaolo Rodola' <[EMAIL PROTECTED]> wrote: > >I'm in a big trouble since I don't know how to find some memory leaks > ... > >The message printed on screen is the following: > > >gc: collectable > >gc: collectable > >gc: collectable > >gc: collectable > >gc: collectable > >gc: collectable > >gc: collectable > > >Since the main module is very big (more than 2800 lines of code) I do > >not understand which objects are not garbage collected. > > They are being garbage collected. That's what the "collectable" part > of the message means. It's just a warning that those objects needed > to be garbage collected because they were refering to each other in > some sort of cycle. While the memory used was being wasted before the > garbage collector ran, it probably doesn't have any negative effect on > your program. > > Ross Ridge Uhm... that's a good news altough it doesn't seem to me that I used any sort of cicle. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: choosing random dynamic port number
On 3 Gen, 23:21, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Emin.shopper Martinian.shopper wrote: > > Is there a good way to choose/assign random dynamic port numbers in python? > > > I had in mind something like the following, but if multiple programs are > > generating random port numbers, is there a way to check if a given port > > number is already taken? > > > def GenerateDynamicPortNumber(): > > "Generate a random dynamic port number and return it." > > # port numbers between 49152 to 65535 are dynamic port numbers > > return 49152 + random.randrange(15000) > > def GenerateDynamicPortNumber(): > return 0 > > (to get the actual number, use getsockname() on the socket after you've > called "bind" on it) > > By using 0 as port number value you let kernel choose a free unprivileged random port: >>> import socket >>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >>> s.bind(('', 0)) >>> s.getsockname() ('0.0.0.0', 3070) -- http://mail.python.org/mailman/listinfo/python-list
stupid/style/list question
I was wondering... To flush a list it is better doing "del mylist[:]" or "mylist = []"? Is there a preferred way? If yes, why? -- http://mail.python.org/mailman/listinfo/python-list
Re: stupid/style/list question
On 8 Gen, 16:45, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Giampaolo Rodola' wrote: > > To flush a list it is better doing "del mylist[:]" or "mylist = []"? > > Is there a preferred way? If yes, why? > > The latter creates a new list object, the former modifies an existing > list in place. > > The latter is shorter, reads better, and is probably a bit faster in > most cases. > > The former should be used when it's important to clear a specific list > object (e.g. if there are multiple references to the list). > > I'm going to use the latter one, thanks. -- http://mail.python.org/mailman/listinfo/python-list
How to get user home directory on Windows
Hi all, I'm trying to use the pywin32 extension to find out the user's home directory but currently I didn't find a solution yet. What I'd need to do is not getting the home directory of the currently logged in user but something like: >>> get_homedir("frank") "C:\home\users\frank" >>> get_homedir("josh") "C:\home\users\josh" Is there a way to do that? I tried to search through the Pywin32 documentation with no luck. In addition I'm not practiced with the Windows API at all. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get user home directory on Windows
On 12 Gen, 17:44, Christian Heimes <[EMAIL PROTECTED]> wrote: > Giampaolo Rodola' wrote: > > Is there a way to do that? > > home = os.path.expanduser("~") > > Christian That gives the home of the *current logged in user*. I need another thing. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get user home directory on Windows
Update. I found a way for getting the home directory of the user but it requires to validate the user by providing username+password: def get_homedir(username, password): token = win32security.LogonUser( username, None, password, win32security.LOGON32_LOGON_NETWORK, win32security.LOGON32_PROVIDER_DEFAULT ) return win32profile.GetUserProfileDirectory(token) What I'd like to do is avoiding the requirement of the password, the same way as if I would on UNIX where it would be enough just using the pwd module: >>> import pwd >>> pwd.getpwnam('user').pw_dir '/home/user' -- http://mail.python.org/mailman/listinfo/python-list
Threaded server
Hi, I'm trying to run an asynchronous FTP server I wrote into a thread for being able to run a test suite against it. The code below is the threaded FTP server code I'm using: --- snippet --- class FTPd(threading.Thread): def __init__(self): self.active = False threading.Thread.__init__(self) def start(self, flag=None): assert not self.active self.flag = flag threading.Thread.start(self) def run(self): assert not self.active ftpd = ftpserver.FTPServer(address, ftp_handler) if self.flag: self.flag.set() self.active = True while self.active: ftpd.server_forever(timeout=1, count=1) ftpd.close() def stop(self): assert self.active self.active = False flag = threading.Event() ftpd = FTPd() ftpd.start(flag) flag.wait() # wait for it to start unittest.main() # run the test suite ftpd.stop() --- /snippet --- Sometimes I get a strange error when all the tests have finished, the server is stopped and Python is exiting: -- Ran 50 tests in 1.515s OK Exception exceptions.TypeError: "'NoneType' object is not callable" in > ignored Exception exceptions.TypeError: "'NoneType' object is not callable" in > ignored I sincerely don't know why that happens but it's likely because I'm not using threads properly. My concern is that this could be caused by a sort of race condition (e.g. Python tries to exit when ftpd.close call is not yet completed). I tried to put a lock in the close() method for waiting the run() method to be completed before returning but I didn't solve the problem. Another information, in case it could be useful, is that this seems to happen with Python 2.3 only. By using 2.4 and Python 2.5 I have no problems. In such cases which is the right way for doing things? Using setDaemon(True)? Could someone point me in the right direction? I've always used the asynchronous approach and dealing with threads is a real pain for me. Thanks in advance. -- Giampaolo -- http://mail.python.org/mailman/listinfo/python-list
Re: Threaded server
On 14 Gen, 12:30, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > Giampaolo Rodola' <[EMAIL PROTECTED]> wrote: > > I'm trying to run an asynchronous FTP server I wrote into a thread for > > being able to run a test suite against it. > > The code below is the threaded FTP server code I'm using: > > > class FTPd(threading.Thread): > > > def __init__(self): > > self.active = False > > threading.Thread.__init__(self) > > > def start(self, flag=None): > > assert not self.active > > self.flag = flag > > threading.Thread.start(self) > > > def run(self): > > assert not self.active > > ftpd = ftpserver.FTPServer(address, ftp_handler) > > if self.flag: > > self.flag.set() > > self.active = True > > while self.active: > > ftpd.server_forever(timeout=1, count=1) > > ftpd.close() > > > def stop(self): > > assert self.active > > self.active = False > > > flag = threading.Event() > > ftpd = FTPd() > > ftpd.start(flag) > > flag.wait() # wait for it to start > > unittest.main() # run the test suite > > ftpd.stop() > > > Sometimes I get a strange error when all the tests have finished, the > > server is stopped and Python is exiting: > > > Ran 50 tests in 1.515s > > > OK > > Exception exceptions.TypeError: "'NoneType' object is not callable" in > > > thod FTPHandler.__del__ of > 127.0.0.1:2 > > 249 at 0xa4b080>> ignored > > Exception exceptions.TypeError: "'NoneType' object is not callable" in > > > thod FTPServer.__del__ of > 127.0.0.1:543 > > 21 at 0x9e1a30>> ignored > > > I sincerely don't know why that happens but it's likely because I'm > > not using threads properly. > > My concern is that this could be caused by a sort of race condition > > (e.g. Python tries to exit when ftpd.close call is not yet > > completed). > > It looks like when python is shutting down, it has removed an object > the ftphandler code relies on. > > I see you attempt to kill the ftp server with ftpd.stop(). That is > good, but you don't wait for the thread to finish (it might take up to > a second in ftpd.server_forever if I understand correctly). > > I expect if you put a self.join() at the end of the stop() method the > problem will go away. > > -- > Nick Craig-Wood <[EMAIL PROTECTED]> --http://www.craig-wood.com/nick- > Nascondi testo tra virgolette - > > - Mostra testo tra virgolette - Tried it but the problem remains. The strange thing is that it sometimes happens, sometimes doesn't. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get user home directory on Windows
Thanks to Tim Golden suggestions I solved my problem. ...In case it would help someone: import _winreg import win32security username = 'Administrator' sid = win32security.ConvertSidToStringSid( win32security.LookupAccountName(None, username)[0] ) key = _winreg.OpenKey( _winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" + "\ \" + sid ) value, type = _winreg.QueryValueEx(key, "ProfileImagePath") print value -- http://mail.python.org/mailman/listinfo/python-list
Python FTP server library 0.3.0 released
Hi, I'm pleased to announce release 0.3.0 of Python FTP Server library (pyftpdlib). http://code.google.com/p/pyftpdlib/ === About === Python FTP server library provides an high-level portable interface to easily write asynchronous FTP servers with Python. Based on asyncore framework pyftpdlib is currently the most complete RFC959 FTP server implementation available for Python programming language. === Major changes === - Implemented more recent FTP commands like MLST, MLSD, FEAT and OPTS. - Iterators are now used for calculating requests requiring long time to complete (LIST and MLSD commands). - Extended the set of assignable user permissions. A complete list of changes including enhancements, bug fixes and instructions for porting old code is available here: http://code.google.com/p/pyftpdlib/wiki/ReleaseNotes03 === More links: === * Source tarball: http://pyftpdlib.googlecode.com/files/pyftpdlib-0.3.0.tar.gz * Online docs: http://code.google.com/p/pyftpdlib/wiki/Tutorial * FAQs: http://code.google.com/p/pyftpdlib/wiki/FAQ * RFCs compliance paper: http://code.google.com/p/pyftpdlib/wiki/RFCsCompliance * Issue tracker: http://code.google.com/p/pyftpdlib/issues/list Thanks, -- Giampaolo Rodola' < g.rodola [at] gmail [dot] com > -- http://mail.python.org/mailman/listinfo/python-list
Why os.path.isabs("/") on Windows returns True?
Hi, I'm trying to solve a jython-related issue and I discovered a different behavior affecting os.path.isabs between CPython and Jython. C:\Python23>python.exe Python 2.3.5 (#62, Feb 8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.path.isabs('/a') True >>> os.path.isabs('/') True >>> os.path >>> C:\dist>jython.bat Jython 2.3a0 on java1.6.0_04 Type "copyright", "credits" or "license" for more information. >>> import os >>> os.path.isabs('/a') False >>> os.path.isabs('/') False >>> os.path >>> Is there a reason why "/" is considered an absolute pathname by CPython? -- http://mail.python.org/mailman/listinfo/python-list
Re: Why os.path.isabs("/") on Windows returns True?
On Feb 1, 9:55 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2008-02-01, Giampaolo Rodola' <[EMAIL PROTECTED]> wrote: > > > I'm trying to solve a jython-related issue and I discovered a > > different behavior affecting os.path.isabs between CPython and > > Jython. > > [...] > > > Is there a reason why "/" is considered an absolute pathname > > by CPython? > > Sure seems like a bug to me. On Unix, "/" is an absolute path. > On windows, "/" is relative to the current device. If you mean "the current drive letter" it's not actually true since "\ \" is used for that: >>> os.getcwd() 'C:\\Python25' >>> os.path.realpath('\\') 'C:\\' >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: Why os.path.isabs("/") on Windows returns True?
On Feb 1, 10:34 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2008-02-01, Giampaolo Rodola' <[EMAIL PROTECTED]> wrote: > > > > > > > On Feb 1, 9:55 pm, Grant Edwards <[EMAIL PROTECTED]> wrote: > >> On 2008-02-01, Giampaolo Rodola' <[EMAIL PROTECTED]> wrote: > > >> > I'm trying to solve a jython-related issue and I discovered a > >> > different behavior affecting os.path.isabs between CPython and > >> > Jython. > > >> [...] > > >> > Is there a reason why "/" is considered an absolute pathname > >> > by CPython? > > >> Sure seems like a bug to me. On Unix, "/" is an absolute path. > >> On windows, "/" is relative to the current device. > > > If you mean "the current drive letter" it's not actually true > > since "\ \" is used for that: > > > >>> os.getcwd() > > 'C:\\Python25' > > >>> os.path.realpath('\\') > > 'C:\\' > > You'll get identical results with "/". Didn't know that. And this is another strange thing since Windows shell does not behave like that: C:\Python25>cd / C:\Python25>cd \ C:\> -- http://mail.python.org/mailman/listinfo/python-list
Change user on UNIX
Hi all. Is there any way to su or login as a different user within a python script? I mainly need to temporarily impersonate another user to execute a command and then come back to the original user. I tried to google a little bit about it but I still didn't find a solution. Thanks in advance. --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Impersonate another user (Guest) on Windows
Hi, I'm trying to write a plug-in for a ftp server of mine to permit the integration with accounts defined on the Windows system. What I basically need is impersonating a user, execute e filesystem call (e.g. create a directory via os.mkdir()) and then switch back to the original user (Administrator). I wrote down this simple class which seems to fit pretty well for my purposes: class WinNTAuthorizer: def impersonate_user(self, username, password): self.impersonated_user_handler = win32security.LogonUser( username, None, password, win32con.LOGON32_LOGON_INTERACTIVE, win32con.LOGON32_PROVIDER_DEFAULT) win32security.ImpersonateLoggedOnUser(self.impersonated_user_handler) def terminate_impersonation(self): win32security.RevertToSelf() self.impersonated_user_handler.Close() What I need now is impersonating the Guest user to handle the anonymous logins (which it's exactly what IIS FTPd does) but I don't know how to do it. Does Guest account has a password or do I have to use something different than LogonUser to manage it? Could someone point me in the right direction? Thanks in advance. --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: Change user on UNIX
Sorry for replying so late. I'll try to describe what I'm actually trying to implement so that maybe it can help you understand a little better. The application is an asynchronous FTP server implementation. I decided that it would be desirable to change the current implementation so that every time a filesystem operation is going to be made I temporarily change the current process ID to reflect the current logged-in user, execute the filesystem call and then switch back to the original process ID. Pseudo code: def STOR(filename): authorizer = UnixAuthorizer() authorizer.impersonate_user(current_logged_in_user) try: f = open(filename, 'w') finally: authorizer.terminate_impersonation() ... The UnixAuthorizer class is expected to provide the mechanism to change the current user (presumably via os.setegid()/os.seteuid()) and then switch back to the original one. Since we're talking about an asynchronous environment I tought that temporarily changing the process ID was the only way to do this. I'm sincerely not skilled enough about the UNIX world to know which are the security implications behind such an approach. Do you think it is reasonable? --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: download timeout vs. socket timeout
On 10 Gen, 03:07, "p." wrote: > i'm using urllib2 in python 2.4 > > wondering how people typically deal with the case in which a download > is too slow. setting the socket timeout only covers those cases where > there is no response in the socket for whatever the timeout period is. > what if, however, i'm getting bits back but want simply to bail out if > the total time to download takes too long? > > i'm trying to avoid creating a whole other thread if possible? You could retrieve your file in little parts and at the same time have a thread which checks how many bytes have been transmitted every second. --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: download timeout vs. socket timeout
I'm sorry. I realized they had already replied when it was too late. --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x
Hi, I'm sure the message I'm going to write will seem quite dumb to most people but I really don't understand the str/bytes/unicode differences introduced in Python 3.0 so be patient. What I'm trying to do is porting pyftpdlib to Python 3.x. I don't want to support Unicode. I don't want pyftpdlib for py 3k to do anything new or different. I just want it to behave exactly the same as in the 2.x version and I'd like to know if that's possible with Python 3.x. Now. The basic difference is that socket.recv() returns a bytes object instead of a string object and that's the thing which confuses me mainly. My question is: is there a way to convert that bytes object into exactly *the same thing* returned by socket.recv() in Python 2.x (a string)? I know I can do: data = socket.recv(1024) data = data.decode(encoding) ...to convert bytes into a string but that's not exactly the same thing. In Python 2.x I didn't have to care about the encoding. What socket.recv() returned was just a string. That was all. Now doing something like b''.decode(encoding) puts me in serious troubles since that can raise an exception in case client and server use a different encoding. As far as I've understood the basic difference I see now is that a Python 2.x based FTP server could handle a 3.x based FTP client using "latin1" encoding or "utf-8" or anything else while with Python 3.x I'm forced to tell my server which encoding to use and I don't know how to deal with that. --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x
On 17 Gen, 02:24, MRAB wrote: > If you're truly working with strings of _characters_ then > 'str' is what you need, but if you're working with strings of _bytes_ > then 'bytes' is what you need. I work with string of characters but to convert bytes into string I need to specify an encoding and that's what confuses me. Before there was no need to deal with that. --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x
On 17 Gen, 03:09, Steven D'Aprano wrote: > On Fri, 16 Jan 2009 17:32:17 -0800, Giampaolo Rodola' wrote: > > On 17 Gen, 02:24, MRAB wrote: > > >> If you're truly working with strings of _characters_ then 'str' is what > >> you need, but if you're working with strings of _bytes_ then 'bytes' is > >> what you need. > > > I work with string of characters but to convert bytes into string I need > > to specify an encoding and that's what confuses me. Before there was no > > need to deal with that. > > In Python 2.x, str means "string of bytes". This has been renamed "bytes" > in Python 3. > > In Python 2.x, unicode means "string of characters". This has been > renamed "str" in Python 3. > > If you do this in Python 2.x: > > my_string = str(bytes_from_socket) > > then you don't need to convert anything, because you are going from a > string of bytes to a string of bytes. > > If you do this in Python 3: > > my_string = str(bytes_from_socket) > > then you *do* have to convert, because you are going from a string of > bytes to a string of characters (unicode). The Python 2.x equivalent code > would be: > > my_string = unicode(bytes_from_socket) > > and when you convert to unicode, you can get encoding errors. A better > way to do this would be some variation on: > > my_str = bytes_from_socket.decode('utf-8') > > You should read this: > > http://www.joelonsoftware.com/articles/Unicode.html > > -- > Steven Thanks, that clarifies a bit even if I still have a lot of doubts. I wish I could do: my_str = bytes_from_socket.decode('utf-8') That would mean avoiding to replace "" with b"" almost everywhere in my code but I doubt it would actually be a good idea. RFC-2640 states that UTF-8 is the preferable encoding to use for both clients and servers but I see that Python 3.x's ftplib uses latin1, for example (bug?). How my server is supposed to deal with that? I think that using bytes everywhere, as Christian recommended, would be the only way to behave exactly like the 2.x version, but that's not easy at all. --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x
On 17 Gen, 03:40, Steve Holden wrote: > Giampaolo Rodola' wrote: > > On 17 Gen, 02:24, MRAB wrote: > > >> If you're truly working with strings of _characters_ then > >> 'str' is what you need, but if you're working with strings of _bytes_ > >> then 'bytes' is what you need. > > > I work with string of characters but to convert bytes into string I > > need to specify an encoding and that's what confuses me. > > Before there was no need to deal with that. > > I don't yet understand why you feel you have to convert what you receive > to a string. In Python 3.0 bytes is the same as a string in 2.6, for > most practical purposes. > > regards > Steve That would help to avoid replacing "" with b"" almost everywhere in my code. --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x
On 17 Gen, 04:43, Terry Reedy wrote: > Giampaolo Rodola' wrote: > > That would help to avoid replacing "" with b"" almost everywhere in my > > code. > > Won't 2to3 do that for you? I used 2to3 against my code but it didn't cover the "" -> b"" conversion (and I doubt it is able to do so, anyway). --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: Totally confused by the str/bytes/unicode differences introduced in Pythyon 3.x
On 17 Gen, 05:26, John Machin wrote: > On Jan 17, 3:08 pm, Steve Holden wrote: > > > Giampaolo Rodola' wrote: > > > On 17 Gen, 04:43, Terry Reedy wrote: > > >> Giampaolo Rodola' wrote: > > >>> That would help to avoid replacing "" with b"" almost everywhere in my > > >>> code. > > >> Won't 2to3 do that for you? > > > > I used 2to3 against my code but it didn't cover the "" -> b"" > > > conversion (and I doubt it is able to do so, anyway). > > > Note that if you are using 2.6 you should first convert your "" quotes > > to b"" - this won't make any practical difference, but then you will be > > able to run 2to3 on your code and (one hopes) covert for 3.0 automatically. > > Perhaps before we get too far down the track of telling the OP what he > should do, we should ask him a little about his intentions: > > Is he porting to 3.0 and abandoning 2.x support completely? > [presumably unlikely] No. > So then what is the earliest 2.x that he wants to support at the same > time as 3.x? [presumably at least 2.5] I currently support Python versions from 2.3 to 2.6 by using un unique codebase. My idea is to support 3.x starting from the last upcoming release. > Does he intend to maintain two separate codebases, one 2.x and the > other 3.x? I think I have no other choice. Why? Is theoretically possible to maintain an unique code base for both 2.x and 3.x? > Else does he intend to maintain just one codebase written in some 2.x > dialect and using 2to3 plus sys.version-dependent code for the things > that 2to3 can't/doesn't handle? I don't think it would worth the effort. > Cheers, > John Thanks a lot --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: vb2py status?
On 17 Gen, 11:05, Vito De Tullio wrote: > axtens wrote: > > So is vb2py dead? If not, any idea when it'll support python 3? > > I don't know this vb2py, but you can do a 2 pass conversion > > [vb] -> (vb2py) -> [py2] -> (2to3) -> [py3] > > -- > By ZeD ...and presumibly get something which doesn't work at all. =) --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
[ANN] Python FTP Server library (pyftpdlib) 0.5.1 released
Hi, I'm pleased to announce release 0.5.1 of Python FTP Server library (pyftpdlib). http://code.google.com/p/pyftpdlib === About === Python FTP server library provides an high-level portable interface to easily write asynchronous FTP servers with Python. Based on asyncore framework pyftpdlib is currently the most complete RFC-959 FTP server implementation available for Python programming language. === Major enhancements === This new version, aside from fixing some bugs, includes the following major enhancements: * A new script implementing FTPS (FTP over SSL/TLS) has been added in the demo directory. * File transfers are now 40% faster thanks to the re-dimensioned application buffer sizes. * ASCII data transfers on Windows are now 200% faster. * Preliminary support for SITE command has been added. * Two new callback methods to handle "file received" and "file sent" events have been added. A complete list of changes including enhancements and bug fixes is available here: http://code.google.com/p/pyftpdlib/wiki/ReleaseNotes05 === More links === * Source tarball: http://pyftpdlib.googlecode.com/files/pyftpdlib-0.5.1.tar.gz * Online docs: http://code.google.com/p/pyftpdlib/wiki/Tutorial * FAQs: http://code.google.com/p/pyftpdlib/wiki/FAQ * RFCs compliance paper: http://code.google.com/p/pyftpdlib/wiki/RFCsCompliance * Issue tracker: http://code.google.com/p/pyftpdlib/issues/list * Mailing list: http://groups.google.com/group/pyftpdlib Thanks, --- Giampaolo Rodola' < g.rodola [at] gmail [dot] com > http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Monitor a FTP site for arrival of new/updated files
On 25 Gen, 21:11, Steve Holden wrote: > pyt...@bdurham.com wrote: > > Any suggestions on a best practice way to monitor a remote FTP site for > > the arrival of new/updated files? I don't need specific code, just some > > coaching on technique based on your real-world experience including > > suggestions for a utility vs. code based solution. > > > My goal is to maintain a local collection of files synced with a remote > > FTP site and when I download a new/updated file locally, run a script to > > process it. The arrival and format of the files that I need to sync with > > are beyond my control (eliminating a rsync solution) ... all I have is a > > generic FTP connection to a specific FTP address. Note: The remote site > > I'm monitoring may have multiple uploads occuring at the same time. > > > My basic strategy is to poll the remote directory on a regular basis and > > compare the new directory listing to a previous snapshot of the > > directory listing. If a file timestamp or size has changed (or a new > > file has appeared), then track this file as a changed file. Once a file > > has been marked as changed, wait polling cycles for the file > > timestamp and size to remain stable, then download it, and trigger a > > local script to process the file. In addition to detecting new or > > changed files, I would compare remote directory listings to my local > > sync folder and delete local files that no longer exist on the remote site. > > > My concern about using a utility is the utility's ability to detect when > > a remote file has finished being updated. I don't want to download files > > that are still in the process of being updated - I only want to download > > new/updated files after they've been closed on the remote site. > > > Any ideas appreciated! > > Well, the ftpmirror will cope with most of what you want to do as it is, > but I am unsure how you can determine whether a file is in the process > of being written on the server. > > regards > Steve > -- > Steve Holden +1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/- Nascondi testo citato > > - Mostra testo citato - If you're going to do that manually through a script, and the server supports it, use MLSD instead of LIST command for listing files and determine their last modification time. My 2 cents --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: unable to print Unicode characters in Python 3
On 26 Gen, 19:16, jefm wrote: > Hi, > while checking out Python 3, I read that all text strings are now > natively Unicode. > In the Python language reference (http://docs.python.org/3.0/reference/ > lexical_analysis.html) I read that I can show Unicode character in > several ways. > "\u" supposedly allows me to specify the Unicode character by hex > number and the format "\N{name}" allows me to specify by Unicode > name. > Neither seem to work for me. > What am I doing wrong ? > > Please see error output below where I am trying to show the EURO sign > (http://www.fileformat.info/info/unicode/char/20ac/index.htm): > > Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information.>>> > print('\u20ac') > > Traceback (most recent call last): > File "", line 1, in > File "c:\python30\lib\io.py", line 1491, in write > b = encoder.encode(s) > File "c:\python30\lib\encodings\cp437.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > position 0: character maps to > > >>> print ("\N{EURO SIGN}") > > Traceback (most recent call last): > File "", line 1, in > File "c:\python30\lib\io.py", line 1491, in write > b = encoder.encode(s) > File "c:\python30\lib\encodings\cp437.py", line 19, in encode > return codecs.charmap_encode(input,self.errors,encoding_map)[0] > UnicodeEncodeError: 'charmap' codec can't encode character '\u20ac' in > position 0: character maps to I have this same issue on Windows. Note that on Python 2.6 it works: Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print unicode('\u20ac') \u20ac This is pretty serious, IMHO, since breaks any Windows software priting unicode to stdout. I've filed an issue on the Python bug tracker: http://bugs.python.org/issue5081 --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Does the Python community really follow the philospy of "Community Matters?"
> Where are the community projects supporting Python? -- besides the > core devlopment. http://pypi.python.org/pypi ...which accidentally says "There are currently 5597 packages here." Not bad uh? --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: 'Address already in use' ... with TCPServer
On 30 Gen, 10:16, "Gabriel Genellina" wrote: > En Fri, 30 Jan 2009 05:43:33 -0200, Mabooka-Mabooka Mbe-Mbe > escribió: > > > setsockopt(REUSEADDR)... > > > What I came up with so far is this: > from SocketServer import * > s = TCPServer( ('', 32123), None) > dir(s) > > ['RequestHandlerClass', '__doc__', '__init__', '__module__', > > 'address_family', 'allow_reuse_address', ... ] > > > Aha! My bet is (was): > s.allow_reuse_address=1 > > should do the trick. > > It's too late then; bind() has already been called. The easiest way is to > define your own derived class: > > import SocketServer > > class TCPServer(SocketServer.TCPServer): > allow_reuse_address = True > > s = TCPServer(...) What's even faster is setting the class attribute right after the module import: >>> import SocketServer >>> SocketServer.TCPServer.allow_reuse_address = True --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: Where to host a (Python) project?
On 31 Gen, 12:46, andrew cooke wrote: > Hi, > > I have a new project, that I just released in beta > (http://www.acooke.org/lepl- a recursive decent parser with full > backtracking). At the moment I am using pypi and setuptools for > distribution (it's a pure python package) and I am happy with hosting > static web pages (the manual and api doc linked to above) on my own > site (I did try the packages.python.org web pages, but it seemed > pointless duplicating my own). > > However, i am thinking I could really do with: > - a mailing list > - simple bug tracking > - subversion > and am wondering which is the best (free) provider for these (the code > is LGPL open source). I'd prefer a mailing list to something like > google groups (although I guess it may be possible to configure a > gateway) and I could open up my personal subversion server, but that > seems like a lot of work (not really that interested in moving to > something other than svn). > > Any recommendations? > > Thanks, > Andrew Google Code. --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: Monitor Internet connections in XP/Vista
On 2 Feb, 10:05, pranav wrote: > Hi Folks, > > I am designing a project for Windows XP/Vista, one part of which is a > background process that monitors internet connections. If the user > tries to connect to any particular site, say myDummySite.com in then > some actions are taken, based on fixed policies. > This can be thought of a mini firewall. > > I am sure there must be some good libraries for this purpose. I need > the names of those libraries. > > Thanks, > > Pranav Prakash I doubt there's something so low-level and platform specific for Python. You could eventually observe what happens on the wire by using libpcap/ Winpcap ("pcapy" and "pypcap" are some python bindings I heard of) but forget about applying policies like "allow/deny this or that traffic" natively. --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: Upgrade 2.6 to 3.0
On 5 Feb, 01:18, Tim Rowe wrote: > 2009/2/4 Scott David Daniels : > > > joviyach wrote: > > >> I am fairly new to Python, the first version I loaded was 2.6. I have > >> since downloaded 3.0 and I was wondering what the best practice for > >> upgrading is? I am using Windows XP Pro for my OS. > > > On Windows, X.Y.* all go in one directory (over-riding each other) > > So the whole 2.6.* family should work just fine alongside the 3.0.* > > Just don't try to have a 2.6 version of Idle and a 3.0 version of Idle > running at the same time! 2.6 WinPy and 3.0 Idle seem to coexist ok, > which is handy when I'm trying to get to grips with the differences > between versions.. > > -- > Tim Rowe Just out of curiosity, am I the only one who think that switching to 3.x right now is not a good idea? --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python 2.6 Quick Reference available
On Feb 10, 8:38 pm, Richard Gruet <"rgruet at free dot fr"> wrote: > The Python 2.6 Quick Reference is available in HTML and PDF formats > athttp://rgruet.free.fr/#QuickRef. > > This time I was helped by Josh Stone for the update. > > As usual, your feedback is welcome (pqr at rgruet.net). > > Cheers, > > Richard Gruet Thanks a lot. PQR is one of the most useful Python related document on Internet, IMHO. --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem building Python extension
On Feb 13, 10:53 am, David Cournapeau wrote: > On Fri, Feb 13, 2009 at 6:30 PM, wrote: > > Hi all, > > > I'm trying to build my first python extensionon a win32 system. I > > followed the description > > inhttp://starship.python.net/crew/mwh/toext/your-first-extension.html, > > but after running > > > C:\Python26\python first-setup.py build_ext -i > > > nothing seems to happen and no file first.pyd is produced. > > > The result from the cmd is the following: > > running build_ext > > building `first` extension > > error: None > > It is a bug in distutils - you reminded me that I did not report it :) > . IIRC, it is caused by the lack of a recognized installation VS 2008. > You should either install VS 2008 (the express vesion is free) or make > sure your VS 2008 is correctly installed. > > Building python 2.6 extensions with mingw is possible as well, but I > think you need to build your own mingw (because python 2.6 requires > msvcr90.dll) - maybe recent mingw have msvcrt90.dll included. > > cheers, > > David I already reported that: http://bugs.python.org/issue4931 --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Re: How to verify whether a process got hanged or still alive.
On 16 Gen, 00:04, neel wrote: > Hi There, > > I want to check the health of IEprocessusing python. I am running an > application on IE. I have to verify that the application is not > crashing the IE. Is there any module which can help me in getting > theprocessstatus? > > Thanks, > Neel By process status you mean knowing whether the process is running, sleeping has been suspended, [...]? Hopefully this should be implemented in psutil soon: http://code.google.com/p/psutil --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list
Quick question about None and comparisons
Sorry for the title but I didn't find anything more appropriate. To have a less verbose code would it be ok doing: if a > b: ...instead of: if a is not None and a > b: ...? Is there any hidden complication behind that? Thanks in advance --- Giampaolo code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Start learning 2.6 or wait for 3.0?
Definitively 2.X. Whether 2.5 or 2.6 doesn't really matter. --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Quick question about None and comparisons
Ok thanks. I'll avoid to do that. --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Using thread in an asyncronous application
Hi, I'm the maintainer of an asynchronous FTP server implementation based on asyncore. Some days ago I thought it would be interesting to add a class offering the possibility to run the asyncore loop into a thread so that a user can run the server without blocking the entire application. It could be useful, for example, in case someone wants to integrate a GUI. Since I'm not good with multi-threaded programming I'd like some opinions about the code I'm going to paste below. The FTPServer class that I inherited in my subclass is the "dispatcher" which listens on port 21 dispatching the incoming connection to an "handler". The polling loop (FTPServer.serve_forever()) is wrapped in the run method. As you can see I acquire and release the lock (threading.Lock) every time I call the polling loop. My question is: is that really necessary? Should I expect some weird behavior by running the main loop into a thread like I did? Thanks in advance class ThreadedFTPServer(FTPServer, threading.Thread): """A modified version of the FTPServer class which wraps the 'serve_forever' polling loop into a thread. The instance returned can be used to start(), stop() and eventually re-start() the server. """ def __init__(self, address, handler): FTPServer.__init__(self, address, handler) threading.Thread.__init__(self) self.__lock = threading.Lock() self.__flag = threading.Event() self.__serving = False self.__stopped = False def __repr__(self): status = [self.__class__.__module__ + "." + self.__class__.__name__] if self.__serving: status.append('active') else: status.append('inactive') status.append('%s:%s' %self.socket.getsockname()[:2]) return '<%s at %#x>' % (' '.join(status), id(self)) def start(self, timeout=1, use_poll=False, map=None): """Start serving until an explicit stop() request. Polls for shutdown every 'timeout' seconds. """ if self.__serving: raise RuntimeError("Server already started") if self.__stopped: # ensure the server can be started again ThreadedFTPServer.__init__(self, self.socket.getsockname (), self.handler) self.__timeout = timeout self.__use_poll = use_poll self.__map = map threading.Thread.start(self) self.__flag.wait() server_forever = start def run(self): self.__serving = True self.__flag.set() while self.__serving: self.__lock.acquire() FTPServer.serve_forever(self, timeout=self.__timeout, count=1, use_poll=self.__use_poll, map=self.__map) self.__lock.release() FTPServer.close_all(self, ignore_all=True) def stop(self): """Stop serving (also disconnecting all currently connected clients) by telling the serve_forever() loop to stop and waits until it does. """ if not self.__serving: raise RuntimeError("Server not started yet") self.__serving = False self.__stopped = True self.join() close = close_all = stop --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Using thread in an asyncronous application
On 29 Nov, 02:24, Aaron Brady <[EMAIL PROTECTED]> wrote: > On Nov 27, 9:03 am, "Giampaolo Rodola'" <[EMAIL PROTECTED]> wrote: > > > > > > > Hi, > > I'm the maintainer of an asynchronous FTP server implementation based > > on asyncore. > > Some days ago I thought it would be interesting to add a class > > offering the possibility to run the asyncore loop into a thread so > > that a user can run the server without blocking the entire > > application. > > It could be useful, for example, in case someone wants to integrate a > > GUI. > > > Since I'm not good with multi-threaded programming I'd like some > > opinions about the code I'm going to paste below. > > > The FTPServer class that I inherited in my subclass is the > > "dispatcher" which listens on port 21 dispatching the incoming > > connection to an "handler". > > The polling loop (FTPServer.serve_forever()) is wrapped in the run > > method. > > As you can see I acquire and release the lock (threading.Lock) every > > time I call the polling loop. > > My question is: is that really necessary? > > Should I expect some weird behavior by running the main loop into a > > thread like I did? > > > Thanks in advance > > I found it hard to read through it. Do you have a smaller abstract > example?- Nascondi testo citato > > - Mostra testo citato - Yeah, sure. I removed all the confusing stuff. Though I didn't tried it it should work: class ThreadedFTPServer(FTPServer, threading.Thread): def __init__(self, address, handler): FTPServer.__init__(self, address, handler) threading.Thread.__init__(self) self.__serving = False def start(self): threading.Thread.start(self) def run(self): self.__serving = True while self.__serving: self.__lock.acquire() FTPServer.serve_forever(self, timeout=1, count=1) self.__lock.release() FTPServer.close_all(self, ignore_all=True) def stop(self): if not self.__serving: raise RuntimeError("Server not started yet") self.__serving = False self.join() --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
How to know when it's possible to bind a socket on an unprivileged port?
Hi, For a purpose of testing I need a function which could tell me whether it is possible to bind sockets on privileged ports or not. I wrote down this simple function. It seems reasonably working to me but I'd like to hear your opinion first. Thanks in advance. import socket, errno def bind_on_privileged_ports(port=21): """Return True if it is possible to bind sockets on privileged ports (< 1024).""" try: s = socket.socket() s.bind(("", port)) except socket.error, err: if err[0] == errno.EACCES: return False s.close() return True --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to know when it's possible to bind a socket on an unprivileged port?
On 11 Dic, 19:09, "Giampaolo Rodola'" wrote: > Hi, > For a purpose of testing I need a function which could tell me whether > it is possible to bind sockets on privileged ports or not. > I wrote down this simple function. It seems reasonably working to me > but I'd like to hear your opinion first. > > Thanks in advance. > > import socket, errno > > def bind_on_privileged_ports(port=21): > """Return True if it is possible to bind sockets on privileged > ports (< 1024).""" > try: > s = socket.socket() > s.bind(("", port)) > except socket.error, err: > if err[0] == errno.EACCES: > return False > s.close() > return True > Just to clarify: I don't really care *which* port to use for binding the socket. I just need to try to bind a socket on a free random privileged port and return True if that has been possible. --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to know when it's possible to bind a socket on an unprivileged port?
Another way (probably more reliable): def bind_on_privileged_ports(): """Return True if it is possible to bind sockets on privileged ports (< 1024).""" for port in range(1, 1024)[::-1]: print port try: s = socket.socket() s.bind((HOST, port)) except socket.error, err: if err[0] == errno.EACCES: return False # speedup else: s.close() return True else: s.close() return False --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python is slow
On 11 Dic, 13:06, Luis M. González wrote: > On Dec 10, 3:42 pm, cm_gui wrote: > > > > > > >http://blog.kowalczyk.info/blog/2008/07/05/why-google-should-sponsor-... > > > I fully agree with Krzysztof Kowalczyk . > > Can't they build a faster VM for Python since they love the language > > so much? > > > Python is SLOW.And I am not comparing it with compiled languages > > like C. > > Python is even slower than PHP! > > > Just go to any Python website and you will know. > > An example is:http://www2.ljworld.com/ > > And this site is created by the creators of Django! > > > And it is not just this Python site that is slow. There are many many > > Python sites which are very slow. And please don’t say that it could > > be the web hosting or the server which is slow — because when so many > > Python sites are slower than PHP sites, it couldn’t be the web > > hosting. Also, Zope/Plone is even slower. > > > Python is slow. Very slow. > > Now seriously, just to finish your idiotic rant, check the Pypy > project: > > http://codespeak.net/pypyhttp://morepypy.blogspot.com > > And if you still think this is not enough, why don't you help these > guys to make it faster? > > Luis- Nascondi testo citato > > - Mostra testo citato - The real (and still unsolved) problem with PyPy is the installation which requires something like a dozen of third-party packages to be installed. Unfortunately it seems there are no plans yet for releasing any Windows/Linux/Mac installer in the near future. --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
ethical questions about global variables
Hi, in a module of mine (ftpserver.py) I'd want to add a (boolean) global variable named "use_gmt_times" to decide whether the server has to return times in GMT or localtime but I'm not sure if it is a good idea because of the "ethical" doubts I'm gonna write below. In first place I've never liked global variables too much and always preferred per-class-instance variables instead. The problem in my case is that I have to use such variable in two separated classes: FTPHandler and VirtualFileSystem. Also, I want that for no reason one class uses times in GMT and the other one local times. Another doubt is the naming convention. PEP-8 states that global variables should use the lower_case_naming_convention but I've seen a lot of library module using the UPPER_CASE_NAMING_CONVENTION. What am I supposed to do about it? Thanks in advance for any comment. --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: ethical questions about global variables
On 16 Dic, 07:23, Michele Simionato wrote: > On Dec 16, 3:45 am, "Giampaolo Rodola'" wrote: > > > Hi, > > in a module of mine (ftpserver.py) I'd want to add a (boolean) global > > variable named "use_gmt_times" to decide whether the server has to > > return times in GMT or localtime but I'm not sure if it is a good idea > > because of the "ethical" doubts I'm gonna write below. > > Global variables have a bad reputation, but they are not > so bad in Python. Notice that: > > 1. global variables in Python are local to the module they > are defined in; > > 2. class names and module names are usually global variables > and nobody complains about that. > > 3. if you use an ALL_CAPS convention it is quite quite clear > that you are using a global variable. > > Actually the ALL_CAPS convention is for constants, but > sometimes I use it for configuration variables too, if > they are set at the beginning and they are never changed > during the running of the program. If you have more than > a single global, it makes sense to introduce a configuration > object, as others have said (this is how typically work) > but if you have a single parameter the confuguration > object is not worth the effort, IMO. > > M. Simionato No, all the other "configurable" variables are offered as class attributes. --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Free place to host python files?
On 16 Dic, 15:56, feba wrote: > On Dec 16, 8:29 am, s...@pobox.com wrote: > > > feba> I'm getting started in python, and it would be helpful to have a > > feba> place to put up various code snippets I've made, so I don't have > > feba> to send them individually to each person I want to show it to. > > feba> I'd prefer to use something that would give me a directory for my > > feba> use only, instead of something where you can only upload one at a > > feba> time. I'd especially like to avoid stuff that uses CAPTCHAs > > feba> and/or forced waiting periods. > > >http://pastebin.com/? > > > -- > > Skip Montanaro - s...@pobox.com -http://smontanaro.dyndns.org/ > > well, ignoring the fact that pastebin doesn't work for me for some > reason, I'm talking about hosting it as a .py downloadable, not a hunk > of text. code.google.com? It also has a SVN repository. --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: ethical questions about global variables
On 16 Dic, 18:01, ianaré wrote: > For anything more complicated than a simple script, I find it easier > to use some sort of config object. This could be a simple dictionnary > type class, where the values can be set/retrieved by the other classes > directly, or a more elaborate class including functions to set/ > retrieve the variables. This way setting/retrieving can be 'smart' -- > possibly looking at other variables, program states, thread count, > whatever, for the requested config option. It also allows for a lot of > expansion down the line if need be, rather than dealing with all sorts > of global variables floating around - which gets annoying pretty > quickly. > > On Dec 15, 9:45 pm, "Giampaolo Rodola'" wrote: > > > > > Hi, > > in a module of mine (ftpserver.py) I'd want to add a (boolean) global > > variable named "use_gmt_times" to decide whether the server has to > > return times in GMT or localtime but I'm not sure if it is a good idea > > because of the "ethical" doubts I'm gonna write below. > > > In first place I've never liked global variables too much and always > > preferred per-class-instance variables instead. > > The problem in my case is that I have to use such variable in two > > separated classes: FTPHandler and VirtualFileSystem. Also, I want that > > for no reason one class uses times in GMT and the other one local > > times. > > > Another doubt is the naming convention. PEP-8 states that global > > variables should use the lower_case_naming_convention but I've seen a > > lot of library module using the UPPER_CASE_NAMING_CONVENTION. What am > > I supposed to do about it? > > > Thanks in advance for any comment. > > > --- Giampaolohttp://code.google.com/p/pyftpdlib/- Nascondi testo citato > > - Mostra testo citato - All the modificable options the library has acquired so far consist of class attributes and I'm ok with that. The only option that should be global is "use_gmt_times" because it is supposed to be used in two classes and I want that both of them use the same parameter. Using a Config class for a single option like "use_gmt_times" is not worth the effort, IMO. --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python 3.0 string formatting - really necessary?
On 19 Dic, 17:01, walterbyrd wrote: > I have not worked with Python enough to really know. But, it seems to > me that more I look at python 3.0, the more I wonder if it isn't a > step backwards. > > To me, it seems that this: > > print "%s=%d" % ('this',99) > > Is much easier, and faster, to type, and is also easier to read and > understand. It also allows people to leverage their knowledge of C. > > This (if it's right) is much longer, and requires more special > characters. > > print( "{0}={1}".format('this',99)) > > Maybe it's worth all the extra trouble, and breaking backward > compatibilty, and all. But, I never had the idea that the old way was > all that big a problem. Of course, I could be wrong. Was the old way > all that big of a problem? You can use the old 2.x syntax also in Python 3.x: C:\>C:\python30\python.exe Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> print("%s=%d" % ('this',99)) this=99 --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
How to "kill" orphaned threads at program exit
Hi, I know that it's not possible to "kill" threads but I'm wondering if does exist some workaround for my problem. I have a test suite which does a massive usage of threads. Sometimes happens that one test fails, the test suite keeps running until the end, and when it's finished the program hangs on and the only way to stop is to kill it manually. I noticed that, at the end of the program, I can call threading.enumerate() and see the pending thread objects: def test_main(): ... start_suite() print threading.enumerate() I was wondering if I can do anything with that. I took a look at test/test_support which has threading_setup() and threading_cleanup() functions. Could such functions be useful to me? Thanks in advance, --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: How to "kill" orphaned threads at program exit
On 28 Dic, 18:47, Roy Smith wrote: > In article > , > "Giampaolo Rodola'" wrote: > > > Hi, > > I know that it's not possible to "kill" threads but I'm wondering if > > does exist some workaround for my problem. > > I have a test suite which does a massive usage of threads. > > Sometimes happens that one test fails, the test suite keeps running > > until the end, and when it's finished the program hangs on and the > > only way to stop is to kill it manually. > > You don't say how you're creating your threads, so I'll assume you're using > threading.Thread(). After creating each thread, and before calling start() > on it, call setDaemon(True). Apparently it doesn't make any difference. A curious thing is that by putting a "print 1" as last instruction the pending threads get killed and the program exits (Windows XP sp3 32 bit). --- Giampaolo http://code.google.com/p/pyftpdlib/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Why not Ruby?
On 31 Dic, 18:55, Xah Lee wrote: > Just spent 3 hours looking into Ruby today. Here's my short impression > for those interested. > > * Why Not Ruby? > http://xahlee.org/UnixResource_dir/writ/why_not_Ruby.html > > plain text version follows: > -- > > Why Not Ruby? > > Xah Lee, 2008-12-31 > > Spent about 3 hours looking into Ruby language today. > > The articles i read in detail are: > > * Wikipedia: Ruby (programming language)�J. Gives general overview. > > * Brief tutorial: "Ruby in Twenty > Minutes"http://www.ruby-lang.org/en/documentation/quickstart/ > > * Personal blog by Stevey Yegge, published in > 2004-10.http://steve.yegge.googlepages.com/ruby-tour > > The Wikipedia gives the best intro and overview in proper context. The > "Ruby in Twenty Minutes" is just 4 pages. It give you a very concrete > intro to Ruby's syntax and semantics. Stevey Yegge's blog doesn't > teach much and rambles, but provide a little personal view. I read it > because his opinions i respect. > > Q: Will you learn Ruby? > > No. For practical application, the lang is some 100 times less useful > than each of Perl, Python, PHP, Javascript. For academic study, > functional langs like Mathematica, Haskell, OCaml, erlang, Qz, are far > more interesting and powerful in almost all aspects. Further, there's > also Perl6, NewLisp, Clojure, Scala... With respect to elegance or > power, these modern lang of the past 5 years matches or exceed Ruby. > > Q: Do you think Ruby lang is elegant? > > Yes. In my opinion, better than Perl, Python, PHP. As a high level > lang, it's far better than Java, C, C++ type of shit. However, i don't > think it is any better than emacs lisp, Scheme lisp, javascript, > Mathematica. Note that Ruby doesn't have a spec, and nor a formal > spec. Javascript has. Ruby's syntax isn't that regular, nor is it > based on a system. Mathemtica's is. Ruby's power is probably less than > Scheme, and probably same as Javascript. > > I also didn't like the fact that ruby uses keyword "end" to indicate > code block much as Pascal and Visual Basic, Logo, do. I don't like > that. > > Q: Won't Ruby be a interesting learning experience? > > No. As far as semantics goes, Ruby is basically identical to Perl, > Python, PHP. I am a expert in Perl and PHP, and have working knowledge > of Python. I already regretted having spent significant amount of time > (roughly over a year) on Python. In retrospect, i didn't consider the > time invested in Python worthwhile. (as it turns out, i don't like > Python and Guido cult, as the lang is going the ways of OOP mumbo- > jumbo with its Python 3 "brand new" future.) There is absolutely > nothing new in Ruby, as compared to Perl, Python, PHP, or Emacs lisp, > Scheme lisp. > > Q: Do you recommend new programers to learn Ruby then? > > Not particularly. As i mentioned, if you are interested in practical > utility, there's already Perl, PHP, Python, Javascript, which are all > heavily used in the computing industry. If you are interested as a > academic exercise, there's Scheme lisp, and much of functional langs > such as OCaml, Haskell, Mathematica, which will teach you a whole lot > more about computer science, features of language semantics, etc. > > Q: Do you condemn Ruby? > > No. I think it's reasonably elegant, but today there are too many > languages, so Ruby don't particularly standout for me. Many of them, > are arguably quite more elegant and powerful than Ruby. See: > Proliferation of Computing Languages. This is not a Ruby group. I recommend you to go waste your time there. --- Giampaolo http://code.google.com/p/pyftpdlib -- http://mail.python.org/mailman/listinfo/python-list