473,324 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

subprocesses and deadlocks

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

Aug 6 '06 #1
1 1115
be*****@gmail.com 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

Aug 6 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jane Austine | last post by:
Running Python 2.3 on Win XP It seems like socket is working interdependently with subprocesses of the process which created socket. ------------------------------------ #the server side >>>...
2
by: Marcos | last post by:
Hi guys, I realise this question has been answered in one form or another many times before but I can't quite find the solution I need. I am trying to run multiple subprocesses from a python...
1
by: AKS | last post by:
I am getting lot of deadlocks in my application. As it is very complex ti avoid deadlocks at this stage of application we have done few steps to lessen the impact. We have added retries after...
1
by: Matt White | last post by:
We've found deadlocks in the trace file that were not captured by our Powerbuilder application. Some deadlocks are trapped or, at least, reported to the user as a db error, and others are...
7
by: Marcus | last post by:
Hello all, I am trying to figure out when it is appropriate to use shared and exclusive locks with InnoDB. Using shared locks (lock in share mode), I can easily create a scenario with 2 clients...
2
by: Dave Kirby | last post by:
I am working on a network management program written in python that has multiple threads (typically 20+) spawning subprocesses which are used to communicate with other systems on the network. This...
9
by: Mike Carr | last post by:
I am running into an issue. Recently I installed IBuySpy Portal and then converted the data source to odp.net. When debugging the app my machine would freeze or become really slow. I can reproduce...
6
by: Greg Stark | last post by:
There's another poster complaining about referential integrity checks causing deadlocks. Unfortunately I've deleted the message so this response (and the archives aren't responding) isn't going to...
3
by: Dara Durum | last post by:
Hi ! Py2.4, Win32. I need to optimize a program that have a speciality: hash (MD5/SHA1) the file contents (many files). Now I do this in a simple python program, because (what a pity) the...
4
by: John Rivers | last post by:
There are many references to deadlock handlers that retry the transaction automatically. But IMO a deadlock is the result of a design flaw that should be fixed. My applications treat...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.