2012-11-06 213 views
0

所以我有一個是給我這個AmbiguousTimeError Django的網站。我保存的產品在更新我的搜索索引之前被暫時暫停時會激活一項工作。看起來像在夏令時時間進行更新,pytz無法弄清楚如何處理它。AmbiguousTimeError芹菜| Django的

我怎樣才能防止這種情況發生下一次的DST小時值班?

[2012-11-06 14:22:52,115: ERROR/MainProcess] Unrecoverable error: AmbiguousTimeError(datetime.datetime(2012, 11, 4, 1, 11, 4, 335637),) 
Traceback (most recent call last): 
    File "/usr/local/lib/python2.6/dist-packages/celery/worker/__init__.py", line 353, in start 
    component.start() 
    File "/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py", line 369, in start 
    self.consume_messages() 
    File "/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py", line 842, in consume_messages 
    self.connection.drain_events(timeout=10.0) 
    File "/usr/local/lib/python2.6/dist-packages/kombu/connection.py", line 191, in drain_events 
    return self.transport.drain_events(self.connection, **kwargs) 
    File "/usr/local/lib/python2.6/dist-packages/kombu/transport/virtual/__init__.py", line 760, in drain_events 
    self._callbacks[queue](message) 
    File "/usr/local/lib/python2.6/dist-packages/kombu/transport/virtual/__init__.py", line 465, in _callback 
    return callback(message) 
    File "/usr/local/lib/python2.6/dist-packages/kombu/messaging.py", line 485, in _receive_callback 
    self.receive(decoded, message) 
    File "/usr/local/lib/python2.6/dist-packages/kombu/messaging.py", line 457, in receive 
    [callback(body, message) for callback in callbacks] 
    File "/usr/local/lib/python2.6/dist-packages/celery/worker/consumer.py", line 560, in receive_message 
    self.strategies[name](message, body, message.ack_log_error) 
    File "/usr/local/lib/python2.6/dist-packages/celery/worker/strategy.py", line 25, in task_message_handler 
    delivery_info=message.delivery_info)) 
    File "/usr/local/lib/python2.6/dist-packages/celery/worker/job.py", line 120, in __init__ 
    self.eta = tz_to_local(maybe_iso8601(eta), self.tzlocal, tz) 
    File "/usr/local/lib/python2.6/dist-packages/celery/utils/timeutils.py", line 52, in to_local 
    dt = make_aware(dt, orig or self.utc) 
    File "/usr/local/lib/python2.6/dist-packages/celery/utils/timeutils.py", line 211, in make_aware 
    return localize(dt, is_dst=None) 
    File "/usr/local/lib/python2.6/dist-packages/pytz/tzinfo.py", line 349, in localize 
    raise AmbiguousTimeError(dt) 
AmbiguousTimeError: 2012-11-04 01:11:04.335637 

編輯:我這個代碼芹菜暫時固定它:

芹菜/工人/ job.py @行120

try: 
    self.eta = tz_to_local(maybe_iso8601(eta), self.tzlocal, tz) 
except: 
    self.eta = None 

我不希望有變化在一個點安裝的應用程序,所以我需要修復我可以在我的代碼:

這運行時,我保存我的應用程序:

self.task_cls.apply_async(
    args=[action, get_identifier(instance)], 
    countdown=15 
) 

我假設我需要,如果我在曖昧的時候我以某種方式檢測並調整倒計時。

回答

1

我想我將不得不清除任務來解決這個問題,但是如何避免這種情況在下一次DST轉換時發生?

不清楚你在做什麼(你沒有顯示任何代碼),但基本上你需要考慮到世界的工作方式。當時間回到一個小時時,當您從本地時間轉換爲UTC(或到另一個區域的本地時間)時,您無法避免出現模糊的時間。

同樣,你應該知道,有「缺口」或「不可能」的時代,在一個合理的冠冕堂皇的本地時間根本不會發生。

我不知道Python給你什麼選擇,但理想情況下,API應該讓你解決模糊的時間,無論你想 - 無論是拋出一個錯誤,給你早先發生,後來發生,或其他。

+0

感謝我試圖澄清。 – leech

+0

@leech:還沒有代碼,也沒有跡象表明你在哪裏使用本地時間或爲什麼。 –

+2

+1您剛剛突破五十萬的口碑那麼恭喜,當你說你會在今年(10萬9個月)年底將達到500K +你是對的。看到這個[評論](http://stackoverflow.com/questions/9203419/practical-example-for-immutable-class#comment11584296_9203445):) –