Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

fix:ImportError: No module named fcntl #2436

Closed
wants to merge 5 commits into
from

Conversation

Projects
None yet
3 participants
Contributor

smallcode commented Mar 17, 2014

fcntl module may not be available in some app engine.

fix:ImportError: No module named fcntl
fcntl module may not be available in some app engine.
Contributor

bak1an commented Mar 17, 2014

Hi @smallcode

I think you should open Trac ticket for this first and provide there more details about environment where mentioned import error occurs.

https://code.djangoproject.com/newticket

Also I'm not sure that silently skipping error is the best way to solve this.

Contributor

smallcode commented Mar 17, 2014

Hi @bak1an
This error has been fixed before, but appeared in version 1.7.
I fix this error is a reference to the previous version 1.6.x:
https://github.com/django/django/blob/stable/1.6.x/django/core/files/locks.py

Owner

timgraham commented Mar 17, 2014

It's a regression caused by 6fe26bd. I don't think the proposed fix is correct though, as it's cause LOCK_SH, etc. to be undefined in this case, rather than 0. The lock and unlock methods won't be correct either.

@smallcode smallcode closed this Mar 18, 2014

@smallcode smallcode reopened this Mar 18, 2014

@smallcode smallcode closed this Mar 18, 2014

@timgraham timgraham reopened this Mar 18, 2014

@timgraham timgraham commented on the diff Mar 18, 2014

django/core/files/locks.py
@@ -24,8 +24,8 @@
def _fd(f):
"""Get a filedescriptor from something which could be a file or an fd."""
return f.fileno() if hasattr(f, 'fileno') else f
-
-
+
@timgraham

timgraham Mar 18, 2014

Owner

don't add whitespace here

@timgraham timgraham commented on the diff Mar 18, 2014

django/core/files/locks.py
- LOCK_EX = fcntl.LOCK_EX
-
- def lock(f, flags):
- ret = fcntl.flock(_fd(f), flags)
- return (ret == 0)
-
- def unlock(f):
- ret = fcntl.flock(_fd(f), fcntl.LOCK_UN)
- return (ret == 0)
+ try:
+ import fcntl
+ LOCK_SH = fcntl.LOCK_SH # shared lock
+ LOCK_NB = fcntl.LOCK_NB # non-blocking
+ LOCK_EX = fcntl.LOCK_EX
+ except (ImportError, AttributeError):
+ LOCK_EX = LOCK_SH = LOCK_NB = 0
@timgraham

timgraham Mar 18, 2014

Owner

It would be better if we could refactor the control flow so we don't have to repeat these lines which also occur after the last else statement in this file.

Owner

timgraham commented Mar 18, 2014

Updated PR: #2442

Could you please review and/or test?

@timgraham timgraham closed this Mar 18, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment