Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#23083 closed Bug (fixed)

dev server autoreload: OSError: [Errno 2] No such file or directory

Reported by: Collin Anderson Owned by: Tim Graham
Component: Core (Management commands) Version: 1.7-rc-1
Severity: Release blocker Keywords:
Cc: cmawebsite@…, hirokiky@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

on django 1.7, sometimes, when I'm saving a file, I'll get this error:

  File "/home/collin/saintmarys/django/core/management/base.py", line 363, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/collin/saintmarys/django/core/management/base.py", line 412, in execute
    output = self.handle(*args, **options)
  File "/home/collin/saintmarys/django/core/management/commands/runserver.py", line 80, in handle
    self.run(**options)
  File "/home/collin/saintmarys/django/core/management/commands/runserver.py", line 89, in run
    autoreload.main(self.inner_run, None, options)
  File "/home/collin/saintmarys/django/utils/autoreload.py", line 324, in main
    reloader(wrapped_main_func, args, kwargs)
  File "/home/collin/saintmarys/django/utils/autoreload.py", line 290, in python_reloader
    reloader_thread()
  File "/home/collin/saintmarys/django/utils/autoreload.py", line 266, in reloader_thread
    change = fn()
  File "/home/collin/saintmarys/django/utils/autoreload.py", line 204, in code_changed
    stat = os.stat(filename)
OSError: [Errno 2] No such file or directory: '/home/collin/saintmarys/main/views.py'

This never happened to me when editing python files on django 1.6. Would it make sense to catch this error and reload when this happens?

Attachments (2)

23083.diff (1.0 KB ) - added by Tim Graham 10 years ago.
23083_2.diff (506 bytes ) - added by Hiroki Kiyohara 10 years ago.
This is the one.

Download all attachments as: .zip

Change History (17)

comment:1 by Tim Graham, 10 years ago

Component: UncategorizedCore (Management commands)
Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted

Seems reasonable. I guess we'd just make this modification?

try:
    state = os.stat(filename)
except OSError:
    return I18N_MODIFIED if filename.endswith('.mo') else FILE_MODIFIED

comment:2 by Collin Anderson, 10 years ago

Yup, that works for me. I guess it's actually pretty easy to reproduce: simply delete the file.

I assume it's another regression from _cached_filenames.

comment:3 by Tim Graham, 10 years ago

Owner: changed from nobody to Tim Graham
Status: newassigned

comment:4 by Tim Graham, 10 years ago

Has patch: set

Here is an actual patch. I used the tutorial and make a request to /polls/, then deleted polls/views.py, but the server didn't reload nor was there an error, so I'm not sure about testing it. I guess writing a test probably isn't feasible but let me know if you have an idea for that.

by Tim Graham, 10 years ago

Attachment: 23083.diff added

comment:5 by Collin Anderson, 10 years ago

I just tried the tutorial also. If I install inotify, things work fine, but when inotify is not installed, I get this issue when deleting polls/views.py.

comment:6 by Collin Anderson, 10 years ago

Actually, I have a feeling this code might not work correctly in the .mo case, but I don't use .mo files.

comment:7 by Tim Graham, 10 years ago

Owner: Tim Graham removed
Status: assignednew

Maybe Claude can look at the issue as he's worked on this code more than I.

comment:8 by Hiroki Kiyohara, 10 years ago

Cc: hirokiky@… added

It's regression caused by this ticket https://code.djangoproject.com/ticket/9722
and not so difficult (Of cause, I don't blame anybody).

And the reason is that the _cached_filenames stores file names even if some files are deleted:

  • Lack of codes to clean up deleted files from _cached_filenames
  • the sys.modules provides modules which is already deleted. so it's difficult to notice the deletion by '_cached_modules == set(sys.modules.values()).

By Timo's patch, os.stat causes OSError every time and the error will be globed.
(I'm not sure about OSErrors provided by os.stat, but it's not good to glob errors blindly)

by Hiroki Kiyohara, 10 years ago

Attachment: 23083_2.diff added

This is the one.

comment:9 by Tim Graham, 10 years ago

Owner: set to Tim Graham
Status: newassigned

I'm trying to write a test.

comment:10 by Tim Graham, 10 years ago

comment:11 by Claude Paroz, 10 years ago

Triage Stage: AcceptedReady for checkin

Thanks for caring for this issue, I was a bit short of time.

comment:12 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In b8cb5ba7081388ef38eccdf8e826747ad3a67e66:

Fixed #23083 -- Fixed runserver reloading when deleting a file.

Thanks Collin Anderson for the report and hirokiky for the fix.

comment:13 by Tim Graham <timograham@…>, 10 years ago

In 4f8a5bd8d0f14280b25e4389b881f9f719159c38:

[1.7.x] Fixed #23083 -- Fixed runserver reloading when deleting a file.

Thanks Collin Anderson for the report and hirokiky for the fix.

Backport of b8cb5ba708 from master

comment:14 by Tim Graham <timograham@…>, 10 years ago

In 57d2b3f2a7e5a7fafb99efc9d93e67bc98feea1b:

Fixed bad usage of rstrip() that caused test failure.

If the temporary file name contained a p or y as its last
characters, it would be stripped. refs #23083.

comment:15 by Tim Graham <timograham@…>, 10 years ago

In d1c08d4758998318eb1a881a3963b63bc89435b8:

[1.7.x] Fixed bad usage of rstrip() that caused test failure.

If the temporary file name contained a p or y as its last
characters, it would be stripped. refs #23083.

Backport of 57d2b3f2a7 from master

Note: See TracTickets for help on using tickets.
Back to Top