[Tutor] Re: A few comparative perl/python questions

Derrick 'dman' Hudson dman@dman.ddts.net
Thu, 22 Aug 2002 22:20:04 -0400


--IrhDeMKUP4DT/M7F
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Jul 28, 2002 at 10:15:32PM +0000, Kyle Babich wrote:
| I just have a few Perl-to-Python questions:
|=20
| Does python have anything like Perl's || die

Yeah, just don't catch the exception and python will "die" (after
printing out the stack trace).  You don't need to do anything special
to die after an error.

| flock(), or seek()
| functions?=20

Yes -- these are actually part of the libc on your system.  The seek()
is a method on file objects.  I'm not sure where flock() is, but I'm
quite sure it is available (on systems where it exists).  The
alternative to flock() is fctl().  On some systems the two locks are
independent, and on others they are the same lock.  File locking is
quite a mess, really.

| (What are they?)

seek() lets you move the current position in a file.
flock() attempts to acquire an *advisory* lock on the file.  I
emphasize 'advisory' because it doesn't prevent a malicious or
otherwise misbehaving program from manipulating the file.

| If Python doesn't have something like flock(), what happens what
| multiple scripts are trying to write to one file at the same time?

The same thing that happens with it :-).  If a program, say 'cat',
doesn't attempt to flock() the file first, or if it ignores it when it
isn't given a lock, then you have an nice race condition and the
results are quite unpredictable.

-D

--=20
You have heard the saying that if you put a thousand monkeys in a room with=
 a
thousand typewriters and waited long enough, eventually you would have a ro=
om
full of dead monkeys.
                                (Scott Adams - The Dilbert principle)
=20
http://dman.ddts.net/~dman/

--IrhDeMKUP4DT/M7F
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iEYEARECAAYFAj1lm9QACgkQO8l8XBKTpRRmygCfdKPvsSXw8u4SVxHkuFyNd3bK
r/4AnRA4f5cB5gvvsi+nMk2EwulURIB4
=z8MM
-----END PGP SIGNATURE-----

--IrhDeMKUP4DT/M7F--