Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > subprocesses and deadlocks

Reply
Thread Tools

subprocesses and deadlocks

 
 
betatim@gmail.com
Guest
Posts: n/a
 
      08-06-2006
Hi,

there are many ways of solving the problem of finite buffer sizes when
talking to a subprocess. I'd usually suggest using select() but today I
was looking for a more readable/understandable way of doing this. Back
in 1997 Guido himself posted a very nice solution, write your input to
a temporary file and then read that from your new process. His posting
can be found here:
http://groups.google.com/group/comp....b0a786d87ba23b

Being a bit puzzled over this usage of tempfile I read its
documentation and as expected it says:

[...] The file is created using mkstemp. It will be destroyed as soon
as it is closed (including an implicit close when the object is garbage
collected). [...] your code should not rely on a temporary file created
using this function having or not having a visible name in the file
system.

so how was Guido planning to get the contents of the file after closing
it? Should we do a tf.flush() instead of the close to ensure everything
is written, then read from it, using subprocess.Popen(....,stdin=tf,..)
and only close it afterwards?

Is it correct to assume that a named temporary file will be (sometimes)
accesible while it has not been closed yet?

cheers,
tim

 
Reply With Quote
 
 
 
 
Simon Forman
Guest
Posts: n/a
 
      08-06-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> there are many ways of solving the problem of finite buffer sizes when
> talking to a subprocess. I'd usually suggest using select() but today I
> was looking for a more readable/understandable way of doing this. Back
> in 1997 Guido himself posted a very nice solution, write your input to
> a temporary file and then read that from your new process. His posting
> can be found here:
> http://groups.google.com/group/comp....b0a786d87ba23b
>
> Being a bit puzzled over this usage of tempfile I read its
> documentation and as expected it says:
>
> [...] The file is created using mkstemp. It will be destroyed as soon
> as it is closed (including an implicit close when the object is garbage
> collected). [...] your code should not rely on a temporary file created
> using this function having or not having a visible name in the file
> system.
>
> so how was Guido planning to get the contents of the file after closing
> it? Should we do a tf.flush() instead of the close to ensure everything
> is written, then read from it, using subprocess.Popen(....,stdin=tf,..)
> and only close it afterwards?
>
> Is it correct to assume that a named temporary file will be (sometimes)
> accesible while it has not been closed yet?
>
> cheers,
> tim


When GvR wrote that around a decade ago, tempfile.mktemp() had not yet
been deprecated. It returns "an absolute pathname of a file that did
not exist at the time the call is made". It does not create a file,
you have to do that yourself.

You're quoting the docs for tempfile.TemporaryFile(). It returns a
"file (or file-like) object", and I'd assume that you would have to
pass this object around without closing it in order to use it in the
manner described in GvR's post.


http://docs.python.org/lib/module-tempfile.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Threads and Deadlocks Mc Osten Ruby 8 03-15-2006 08:32 PM
deadlocks ndxp@hotmail.com Java 31 12-22-2005 04:42 PM
Deadlocks Mike Carr ASP .Net 9 07-23-2004 07:31 PM
Automatically detecting deadlocks? Rogan Dawes Java 2 05-06-2004 06:27 AM
ASP.NET Deadlocks Martin Blackstone [MVP - Exchange] ASP .Net 6 08-24-2003 02:56 AM



Advertisments