Python Forum
OSError: [Errno 26] Text file busy: '/var/tmp/tmp5qbeydbp
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
OSError: [Errno 26] Text file busy: '/var/tmp/tmp5qbeydbp
#1
Hey,

Im using python3 and i have this code :
                import tempfile
                temp_file = tempfile.mkstemp(dir="/var/tmp")
                with open (temp_file[1], "w+b") as tf:
                    tf.write(result.content)
                    tf.close()
                os.chmod(temp_file[1], 0o755)

                if 'args' in command[cmd_type]:
                    args = [temp_file[1]] +  command[cmd_type]['args']
                else:
                    args = [temp_file[1]]
        result = subprocess.run(
            args,
            stdout=subprocess.PIPE,
            universal_newlines=True,
        ).stdout.strip()
Im creating a tempfile that is a binary file and i get this value from code:
/var/tmp/tmp5qbeydbp - that this is the file that has been created and i try to run it
in the last subprocess run but i get this error:

client_1  |   File "/usr/local/lib/python3.7/subprocess.py", line 472, in run
client_1  |     with Popen(*popenargs, **kwargs) as process:
client_1  |   File "/usr/local/lib/python3.7/subprocess.py", line 775, in __init__
client_1  |     restore_signals, start_new_session)
client_1  |   File "/usr/local/lib/python3.7/subprocess.py", line 1522, in _execute_child
client_1  |     raise child_exception_type(errno_num, err_msg, err_filename)
client_1  | OSError: [Errno 26] Text file busy: '/var/tmp/tmp5qbeydbp'
Why is file always busy ? it started when i added the chmod command.
but without it, it doesnt have permission to run.

Thanks.
Reply
#2
Hi,
This is indeed weird and I have been thinking it over. I did not try your code but I've read the manual of tempfile.mkstemp(). There I read "... returns a tuple containing an OS-level handle to an open file (as would be returned by os.open())...". This means the "mkstemp()" already opens the file. So it may be spurious that you also open the file (with open (temp_file[1], "w+b") as tf:).
Perhaps you should not open the file but write directly to it (os.write(temp_file[0], result.content)) and then close the file (os.close(temp_file[0])).
Let us know if this works.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error (Errno 2), File upload with the Flask framework and a public IP Username_Python1 0 248 Mar-28-2024, 01:46 PM
Last Post: Username_Python1
  OSError occurs in Linux. anna17 2 279 Mar-23-2024, 10:00 PM
Last Post: snippsat
  OSError with SMPT script Milan 0 759 Apr-28-2023, 01:34 PM
Last Post: Milan
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,111 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Need Help: FileNotFoundError:[Errno 2] No such file or directory python202209 5 2,634 Sep-12-2022, 04:50 AM
Last Post: python202209
  OSERROR When mkdir Oshadha 4 1,700 Jun-29-2022, 08:50 AM
Last Post: DeaD_EyE
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,655 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Converted Pipe Delimited text file to CSV file atomxkai 4 6,955 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  FileNotFoundError: [Errno 2] No such file or directory: 'word2vec.model' Anldra12 6 6,028 Jul-07-2021, 07:29 AM
Last Post: Anldra12
  FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles Anldra12 10 5,774 Jun-11-2021, 04:48 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020