Error Telling The Debug Trace File Position Bad File Descriptor
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting
Errno Bad File Number
ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join errno 9 bad file descriptor socket the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a
Errno 9 Socket
minute: Sign up lseek/write suddenly returns -1 with errno = 9 (Bad file descriptor) up vote 5 down vote favorite My application uses lseek() to seek the desired position to write data. The file is successfully opened using open() and read errno 9 my application was able to use lseek() and write() lots of times. At a given time, for some users and not easily reproducable, lseek() returns -1 with an errno of 9. File is not closed before this and the filehandle (int) isn't reset. After this, another file is created; open() is okay again and lseek() and write() works again. To make it even worse, this user tried the complete sequence again and all was well. So my question is, can the OS #define ebadf 9 /* bad file number */ close the file handle for me for some reason? What could cause this? A file indexer or file scanner of some sort? What is the best way to solve this; is this pseudo code the best solution? (never mind the code layout, will create functions for it) int fd=open(...); if (fd>-1) { long result = lseek(fd,....); if (result == -1 && errno==9) { close(fd..); //make sure we try to close nicely fd=open(...); result = lseek(fd,....); } } Anybody experience with something similar? Summary: file seek and write works okay for a given fd and suddenly gives back errno=9 without a reason. c file-io handle seek share|improve this question edited Mar 30 '10 at 12:23 DevSolar 36.9k1270131 asked Mar 30 '10 at 12:01 Ger Teunis 4881127 My code won't compile if I try to open(...); Odd. –Tim Post♦ Mar 30 '10 at 12:47 1 You know pseudo code right? –Ger Teunis Mar 30 '10 at 13:05 If lseek() fails with EBADF, you can be pretty sure that close() on the same file descriptor will also fail with EBADF. And since you don't check your re-open or re-seek calls, anything could be happening. –Jonathan Leffler Mar 30 '10 at 13:44 @ Ger Teunis: If what you post is pseudocode, mark it as such, so people won't complain (as Tim did) or simply tell you "works for me". Avoid posting pseudocode if at all possible - the process of find
help? Post your question and get tips & solutions from a community of 418,546 IT Pros & Developers. It's quick & easy. file.readlines() - gives me error (bad file descriptor) P: n/a wordsender Hey guys,
Connect Errno 9
I can't figure this one out, why is this simple script giving me problems? logfile=file(r'test.txt','w') errno 14 logfile.write('datetime') test=logfile.readlines() When I run it I get the error message: Traceback (most recent call last): File "C:\Documents and Settings\Gregory\My Documents\Get New Great
C Errno
Job\testfile.py", line 3, in ? test=logfile.readlines() IOError: [Errno 9] Bad file descriptor I'm running Windows XP, Python 2.3.3 (#51, Dec 18 2003, 20:22:39) [MSC v.1200 32 bit (Intel)] on win32 Any help would be greatly appricated. Thanks, Greg http://stackoverflow.com/questions/2544898/lseek-write-suddenly-returns-1-with-errno-9-bad-file-descriptor Jul 18 '05 #1 Post Reply Share this Question 9 Replies P: n/a Aldo Cortesi Thus spake wo********@gmail.com (wo********@gmail.com): Hey guys, I can't figure this one out, why is this simple script giving me problems? logfile=file(r'test.txt','w') ^^^ You've opened the file in write mode. To read from the file, you'll have to reopen it in read mode ("r"). Also, if the file you're dealing with really is a log file, you probably want don't want https://bytes.com/topic/python/answers/40073-file-readlines-gives-me-error-bad-file-descriptor to open it in write mode for writing information either, since that will truncate the file and lose previously logged information. Try append mode ("a") instead. Cheers, Aldo -- Aldo Cortesi al**@nullcube.com http://www.nullcube.com Off: (02) 9283 1131 Mob: 0419 492 863 Jul 18 '05 #2 P: n/a Gurpreet Sachdeva I tried logfile=file(r'test.txt','w+') logfile.write('datetime') test=logfile.readlines() print test I got : Open an encoded file using the given mode and return a wrapped version providing transparent encoding/decoding. Note: The wrapped version will only accept the object format defined by the codecs, i.e. Unicode objects for most builtin codecs. Output is also codec dependent and will usually by Unicode as well. Files are always opened in binary mode, even if no binary mode was specified. This is done to avoid data loss due to encodings using 8-bit values. The default file mode is 'rb' meaning to open the file in binary read mode. encoding specifies the encoding which is to be used for the file. errors may be given to define the error handling. It defaults to 'strict' which causes ValueErrors to be raised in case an encoding and a hell lot of junk. Can anyone explain that??? AFAIK w+ was ment for opening a file for both writting and reading... Regards, Garry On Thu, 6 Jan 2005 12:03:27 +0530, Vishnu