classification
Title: Mysterious failure under Windows
Type: Stage:
Components: Versions: Python 2.5
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: akineko, ggenellina, loewis
Priority: normal Keywords:

Created on 2007-08-31 19:01 by akineko, last changed 2007-09-01 05:34 by loewis. This issue is now closed.

Messages (6)
msg55537 - (view) Author: Aki (akineko) Date: 2007-08-31 19:14
Hi,

I'm not sure this is a right place to write in the problem I found.
What I found was:
(1) create a thread
(2) open a file in the thread
(3) everything works fine under Solaris
(4) Openning a file in the thread fails intermittenly under Windows
Not always it fails.
The file is there but it returns:
  File "h:\prj\socgear\unidbg\tkunidbg\sub.py", line 94, in thread_worker
    fd = open(fn, 'rb')
IOError: [Errno 2] No such file or directory: './XXX.dat'
(5) The problem goes away (under Windows) if I have the main thread wait
until the file is opened using Event.

//

The program also uses Tkinter but I'm not sure that is relevant.
I cannot submit the whole program as it is too big to submit.

Aki-
msg55542 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-08-31 22:21
I don't see the problem. When open() reports that the file does not
exist, the most likely reason is that it really does not exist. Perhaps
it has not been created, yet, and you need to wait until it has been
created before you can open it?
msg55543 - (view) Author: Aki (akineko) Date: 2007-08-31 22:55
I know it is hard to believe.
I spent days to try out many things.

For example, I added the following:
            try:
                print os.path.isfile(fn)  <<<---
                fd = open(fn, 'rb')
                crypted = fd.read()
                fd.close()
                idx = crypted.index('\n')
            except (IOError, OSError, ValueError,):
                raise

When I run, I got following cases randomly:
(1) True, Open successfully
(2) True, Open failed
(3) False, Open failed
(4) False, Open successfully

The file is a binary data file and is already sitting in the directory
before the execution of the program.

I know that for other people it is very difficult to work on such case.
But this is something to do with threading under windows.

Aki-
msg55544 - (view) Author: Gabriel Genellina (ggenellina) Date: 2007-09-01 01:03
Does the file exist before program is started, and remains after 
program finishes?
If it is your program which creates the file, you may have a race 
condition. Maybe some delays/retries will be enough, or perhaps you 
will have to use some other syncronization mechanisms.

Also, I see you use a relative path. Do you change the current 
directory (with os.chdir or similar)?
msg55545 - (view) Author: Aki (akineko) Date: 2007-09-01 01:11
Sorry to disappoint you but ...
(1) Does the file exist before program is started, and remains after
program finishes?
Yes and Yes
(2) Do you change the current directory (with os.chdir or similar)?
No. The file is in the current directory where the program was invoked.

//

Probably, only way to settle this is to create a small test case.
But I'm not sure if that is easy.
(For example, this problem won't occur if no activity in the main thread.)

Aki-
msg55550 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-09-01 05:34
I'm closing this as "works for me" now. It cannot possibly be a bug in
Python, since the error was created by the operating system; Python does
not make it up randomly. I also doubt that the operating system will
arbitrarily report that a file is not present if the calling process
uses threads.

So if you can come up with a reproducible test case, please submit a new
bug report. Otherwise, you are on your own figuring out what's going on.
History
Date User Action Args
2007-09-01 05:34:55loewissetstatus: open -> closed
resolution: works for me
messages: + msg55550
2007-09-01 01:11:14akinekosetmessages: + msg55545
2007-09-01 01:03:04ggenellinasetnosy: + ggenellina
messages: + msg55544
2007-08-31 22:55:25akinekosetmessages: + msg55543
2007-08-31 22:21:02loewissetnosy: + loewis
messages: + msg55542
2007-08-31 19:14:12akinekosetnosy: + akineko
messages: + msg55537
2007-08-31 19:01:38akinekocreate