[py-dev] Request for enhancing Exception handling in execnet
Walter Dörwald
walter at livinglogic.de
Wed May 7 12:04:29 CEST 2008
Gerard Petersen wrote:
> Guido,
>
> Thanx for the code snippet. Initially I wanted to keep the code that goes
> remote as clean as possible (somebody told me ... ;-) but
> the code you came up with does seem good.
>
> The actual issue is somewhat more elaborate. I also have remote functions that
> read files, and a predicatble situation is that a file might not be there
> remotely. Since this is a possibiltity and not an exception as such, (next to
> a "permission denied" which is). There is also the possibility to return an
> error value along all the time. You then would still need some error handling
> remotely but the last line in your function would be something like "return
> contents, error".
> "Error" containing a level from zero upwards. I'll see if I can combine a
> setup like that with the "isinstance" function.
>
> More on the way, Thanx guys!!
You might take a look at the ll.url module which is part of XIST
(available from: http://www.livinglogic.de/Python/Download.html
ll.url implements an ssh URL scheme which supports all file operations
remotely:
>>> from ll import url
>>> u = url.URL("ssh://root@www.example.org/~/")
>>> u.listdir(context=url.Context())
[URL('.bash_history'),
URL('.profile'),
URL('.bashrc'),
...
>>> u = url.URL("ssh://root@www.example.org/~/.bash_history")
>>> f = u.open("rb", context=url.Context())
>>> f.readline()
'/etc/init.d/tomcat stop\n'
>>> f.readline()
'ps waux | grep tomcat\n'
It mirrors exceptions locally:
>>> u = url.URL("ssh://root@www.example.org/~/does-not-exist")
>>> f = u.open("rb", context=url.Context())
[...]
IOError: [Errno 2] No such file or directory: '/root/does-not-exist'
(of course this only works for builtin exceptions)
And of course ll.url uses py.execnet for communicating with the remote host.
Hope that helps!
Servus,
Walter
More information about the py-dev
mailing list