我有一个 django 应用程序,我使用 uWSGI 和 nginx 设置 Django 和我的 Web 服务器。我有一个设置文件访问时间的函数,这是我的函数:
from shutil import move
from time import mktime
from os import utime
def spool(self, time=None):
if time:
try:
time = mktime(time.timetuple())
utime(path(self.tempdir) / path(self.filename), (time, time))
except (error, AttributeError, OverflowError, ValueError):
raise InvalidTimeError
try:
move(path(self.tempdir) / path(self.filename),
path(self.spool_dir) / path(self.filename))
except IOError:
raise NoSpoolPermissionError
当我用 python 命令运行这个函数时,访问时间是正确的:
root@demo:~# stat /var/spool/asterisk/outgoing/tmp_4BmDa.call
File: `/var/spool/asterisk/outgoing/tmp_4BmDa.call'
Size: 56 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 561550 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2013-08-21 11:27:30.000000000 +0430
Modify: 2013-08-21 11:27:30.000000000 +0430
Change: 2013-08-21 11:24:00.142143170 +0430
Birth: -
但是当我在我的 django 应用程序中运行该函数时,输出是:
root@demo:~# stat /var/spool/asterisk/outgoing/tmp_4BmDa.call
File: `/var/spool/asterisk/outgoing/tmp_4BmDa.call'
Size: 242 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 561542 Links: 1
Access: (0666/-rw-rw-rw-) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2013-08-21 21:15:00.000000000 +0430
Modify: 2013-08-21 21:15:00.000000000 +0430
Change: 2013-08-21 11:44:42.982093206 +0430
Birth: -
如您所见,访问时间是 <<2013-08-21 21:15:00>> 但它必须是 <<2013-08-21 11:44:42>> 我不知道发生了什么。linux date 命令输出为:
root@demo:~# date
Wed Aug 21 11:44:55 IRDT 2013
和 python 日期时间输出:
>>> datetime.datetime.now()
datetime.datetime(2013, 8, 21, 11, 45, 57, 886360)