Windows: temp wieder löschen -> PermissionError...

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
Benutzeravatar
jens
Python-Forum Veteran
Beiträge: 8502
Registriert: Dienstag 10. August 2004, 09:40
Wohnort: duisburg
Kontaktdaten:

Versuche unittests von https://github.com/jedie/bootstrap_env auf Windows laufen zu lassen.

Es kommt u.a. zu einem PermissionError wenn die Temorären Dateien gelöscht werden sollen.

Der relevante Code sieht ungefähr so aus:

Code: Alles auswählen

class TempDir():
    def __init__(self, prefix=""):
        self.tempfolder = tempfile.mkdtemp(prefix=prefix)

    def __enter__(self):
        return self.tempfolder

    def __exit__(self, exc_type, exc_value, traceback):
        shutil.rmtree(self.tempfolder)


class TestBoot(BaseExampleTestCase):
    def test_boot_git_readonly(self):
        with TempDir(prefix="bootstrap_test_boot_git_readonly_") as tempfolder:
            # teste rum...
Auf appveyor.com sieht es so aus:

Code: Alles auswählen

ERROR: test_boot_git_readonly (bootstrap_env.tests.test_boot.TestBoot)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\bootstrap_env\src\bootstrap-env\bootstrap_env\tests\test_boot.py", line 175, in test_boot_git_readonly
    self.assertIn("New python executable in %s/bin/python" % tempfolder, output)
  File "C:\bootstrap_env\src\bootstrap-env\bootstrap_env\tests\utils\base_unittest.py", line 79, in __exit__
    shutil.rmtree(self.tempfolder)
  File "C:\Python27\Lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Python27\Lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Python27\Lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Python27\Lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Python27\Lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Python27\Lib\shutil.py", line 252, in rmtree
    onerror(os.remove, fullname, sys.exc_info())
  File "C:\Python27\Lib\shutil.py", line 250, in rmtree
    os.remove(fullname)
WindowsError: [Error 5] Access is denied: 'c:\\users\\appveyor\\appdata\\local\\temp\\bootstrap_test_boot_git_readonly_nak2xk\\src\\bootstrap-env\\.git\\objects\\pack\\pack-cf9c2d47351e4132d8a4a99bef0ec17482170ccd.idx'
-> https://ci.appveyor.com/project/jedie/b ... s8f91#L249

Lokal auf 8.1 so:

Code: Alles auswählen

Traceback (most recent call last):
  File "V:\workspace\bootstrap-env\bootstrap_env\tests\test_boot.py", line 187,
in test_boot_git_readonly
    self.assertIn("Successfully installed bootstrap-env", log_content)
  File "V:\workspace\bootstrap-env\bootstrap_env\tests\utils\base_unittest.py",
line 79, in __exit__
    shutil.rmtree(self.tempfolder)
  File "C:\Users\jens\AppData\Roaming\bootstrap_env\lib\shutil.py", line 478, in
 rmtree
    return _rmtree_unsafe(path, onerror)
  File "C:\Users\jens\AppData\Roaming\bootstrap_env\lib\shutil.py", line 368, in
 _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\jens\AppData\Roaming\bootstrap_env\lib\shutil.py", line 368, in
 _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\jens\AppData\Roaming\bootstrap_env\lib\shutil.py", line 368, in
 _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\jens\AppData\Roaming\bootstrap_env\lib\shutil.py", line 368, in
 _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\jens\AppData\Roaming\bootstrap_env\lib\shutil.py", line 368, in
 _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\jens\AppData\Roaming\bootstrap_env\lib\shutil.py", line 373, in
 _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Users\jens\AppData\Roaming\bootstrap_env\lib\shutil.py", line 371, in
 _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 5] Zugriff verweigert: 'x:\\temp\\bootstrap_test_boot
_git_readonly_c99_odba\\src\\bootstrap-env\\.git\\objects\\pack\\pack-267165bf5a
6c86d4637de920e960efb67356a872.idx'

Also einmal WindowsError und einmal PermissionError :K


Überlege gerade, ob ich mit atexit aufräumen sollte?!?

(Wobei ich erstmal den Fehler ignorieren werde...)

GitHub | Open HUB | Xing | Linked in
Bitcoins to: 1JEgSQepxGjdprNedC9tXQWLpS424AL8cd
Benutzeravatar
sparrow
User
Beiträge: 4599
Registriert: Freitag 17. April 2009, 10:28

Sieht mir fast so aus, als würde da noch ein Programm den Lock auf der Datei haben.
Hast du einmal probiert einen Augenblick zu warten oder den Fehler max x-Mal abzufangen und dazwischen kurz zu warten?
BlackJack

Unter Windows machen bei solchen Aktionen Virenscanner gerne mal Probleme.
Benutzeravatar
jens
Python-Forum Veteran
Beiträge: 8502
Registriert: Dienstag 10. August 2004, 09:40
Wohnort: duisburg
Kontaktdaten:

Virenscanner ist lokal an. Wäre ein Möglichkeit. Aber ich denke nicht, das auf appveyor.com einer läuft... Aber wer weiß ;)

Ich teste mal das mit dem warten...

GitHub | Open HUB | Xing | Linked in
Bitcoins to: 1JEgSQepxGjdprNedC9tXQWLpS424AL8cd
Benutzeravatar
jens
Python-Forum Veteran
Beiträge: 8502
Registriert: Dienstag 10. August 2004, 09:40
Wohnort: duisburg
Kontaktdaten:

Warten nützt nichts:

Code: Alles auswählen

Error: Can't cleanup temp files: [WinError 5] Zugriff verweigert: 'x:\\temp\\boo
tstrap_test_boot_git_readonly_kz6sp7kc\\src\\bootstrap-env\\.git\\objects\\pack\
\pack-267165bf5a6c86d4637de920e960efb67356a872.idx'
  File "V:\workspace\bootstrap-env\bootstrap_env\tests\utils\base_unittest.py",
line 87, in _rm_tree_temp
    shutil.rmtree(self.tempfolder)
Wait 0.5...
Try again...
Error: Can't cleanup temp files: [WinError 5] Zugriff verweigert: 'x:\\temp\\boo
tstrap_test_boot_git_readonly_kz6sp7kc\\src\\bootstrap-env\\.git\\objects\\pack\
\pack-267165bf5a6c86d4637de920e960efb67356a872.idx'
  File "V:\workspace\bootstrap-env\bootstrap_env\tests\utils\base_unittest.py",
line 87, in _rm_tree_temp
    shutil.rmtree(self.tempfolder)
Wait 1.0...
Try again...
Error: Can't cleanup temp files: [WinError 5] Zugriff verweigert: 'x:\\temp\\boo
tstrap_test_boot_git_readonly_kz6sp7kc\\src\\bootstrap-env\\.git\\objects\\pack\
\pack-267165bf5a6c86d4637de920e960efb67356a872.idx'
  File "V:\workspace\bootstrap-env\bootstrap_env\tests\utils\base_unittest.py",
line 87, in _rm_tree_temp
    shutil.rmtree(self.tempfolder)
Wait 2.0...
Try again...
Error: Can't cleanup temp files: [WinError 5] Zugriff verweigert: 'x:\\temp\\boo
tstrap_test_boot_git_readonly_kz6sp7kc\\src\\bootstrap-env\\.git\\objects\\pack\
\pack-267165bf5a6c86d4637de920e960efb67356a872.idx'
  File "V:\workspace\bootstrap-env\bootstrap_env\tests\utils\base_unittest.py",
line 87, in _rm_tree_temp
    shutil.rmtree(self.tempfolder)

GitHub | Open HUB | Xing | Linked in
Bitcoins to: 1JEgSQepxGjdprNedC9tXQWLpS424AL8cd
Sirius3
User
Beiträge: 18335
Registriert: Sonntag 21. Oktober 2012, 17:20

@jens: bist Du Dir sicher, dass Du auch alle Dateien ordnungsgemäß wieder schließt? Gerade bei with sind die lokalen Variablen ja noch aktiv, da hilft dann auch kein Warten.
Benutzeravatar
jens
Python-Forum Veteran
Beiträge: 8502
Registriert: Dienstag 10. August 2004, 09:40
Wohnort: duisburg
Kontaktdaten:

Gute Frage... Womöglich... Wobei ich eigentlich IMHO nicht selbst auf die .git Dateien zugreife... Die kommen von einem "pip install -e"...

GitHub | Open HUB | Xing | Linked in
Bitcoins to: 1JEgSQepxGjdprNedC9tXQWLpS424AL8cd
Antworten