以下のコード例で次のエラーが発生します。このコードは過去に正常に機能していたため、エラーの原因が何であるかはわかりません。私はPython 2.7を使用しています
AttributeError: 'module' object has no attribute 'allocate_lock'
問題を含む最小限の例を次に示します。
import pandas as pd
import pytz
from datetime import datetime, timedelta
from dateutil import rrule
start = pd.Timestamp('1900-01-01', tz='UTC')
end_base = pd.Timestamp('today', tz='UTC')
end = end_base + timedelta(days=365)
def canonicalize_datetime(dt):
return datetime(dt.year, dt.month, dt.day, tzinfo=pytz.utc)
def get_rules(start, end):
rules = []
start = canonicalize_datetime(start)
end = canonicalize_datetime(end)
weekends = rrule.rrule(
rrule.YEARLY,
byweekday=(rrule.SA, rrule.SU),
cache=True,
dtstart=start,
until=end
)
rules.append(weekends)
return rules
rules = get_rules(start, end)
完全なトレースバック
Traceback (most recent call last):
File "/Users/mac/Documents/test.py", line 48, in <module>
rules = get_rules(start, end)
File "/Users/mac/Documents/test.py", line 42, in get_rules
until=end
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dateutil/rrule.py", line 239, in __init__
super(rrule, self).__init__(cache)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dateutil/rrule.py", line 90, in __init__
self._cache_lock = _thread.allocate_lock()
AttributeError: 'module' object has no attribute 'allocate_lock'
dateutil ソース コードとユーザー @PatrickCollins から、問題は次のように生成できます。
import _thread
_thread.allocate_lock()