BUG: sys.exc_clear is py2 only.

This commit is contained in:
Scott Sanderson
2016-11-22 16:34:53 -05:00
parent 7a5f5da6b2
commit 16e78bbccd
2 changed files with 19 additions and 3 deletions
+10 -3
View File
@@ -22,7 +22,6 @@ import pandas as pd
from contextlib2 import ExitStack from contextlib2 import ExitStack
from pandas.tseries.tools import normalize_date from pandas.tseries.tools import normalize_date
import numpy as np import numpy as np
import sys
from itertools import chain, repeat from itertools import chain, repeat
from numbers import Integral from numbers import Integral
@@ -111,6 +110,7 @@ from zipline.utils.input_validation import (
from zipline.utils.calendars.trading_calendar import days_at_time from zipline.utils.calendars.trading_calendar import days_at_time
from zipline.utils.cache import CachedObject, Expired from zipline.utils.cache import CachedObject, Expired
from zipline.utils.calendars import get_calendar from zipline.utils.calendars import get_calendar
from zipline.utils.compat import exc_clear
import zipline.utils.events import zipline.utils.events
from zipline.utils.events import ( from zipline.utils.events import (
@@ -2343,9 +2343,16 @@ class TradingAlgorithm(object):
Internal implementation of `pipeline_output`. Internal implementation of `pipeline_output`.
""" """
today = normalize_date(self.get_datetime()) today = normalize_date(self.get_datetime())
data = NO_DATA = object()
try: try:
data = self._pipeline_cache.unwrap(today) data = self._pipeline_cache.unwrap(today)
except Expired: except Expired:
# We can't handle the exception in this block because in Python 3
# sys.exc_info isn't cleared until we leave the block. See note
# below for why we need to clear exc_info.
pass
if data is NO_DATA:
# Try to deterministically garbage collect the previous result by # Try to deterministically garbage collect the previous result by
# removing any references to it. There are at least three sources # removing any references to it. There are at least three sources
# of references: # of references:
@@ -2358,8 +2365,8 @@ class TradingAlgorithm(object):
# We remove the above sources of references in reverse order: # We remove the above sources of references in reverse order:
# 3. Clear the traceback. # 3. Clear the traceback. This is no-op in Python 3.
sys.exc_clear() exc_clear()
# 2. Clear the .loc/.iloc caches. # 2. Clear the .loc/.iloc caches.
clear_dataframe_indexer_caches( clear_dataframe_indexer_caches(
+9
View File
@@ -1,4 +1,5 @@
from six import PY2 from six import PY2
import sys
if PY2: if PY2:
@@ -8,9 +9,17 @@ if PY2:
mappingproxy.argtypes = [py_object] mappingproxy.argtypes = [py_object]
mappingproxy.restype = py_object mappingproxy.restype = py_object
def exc_clear():
sys.exc_clear()
else: else:
from types import MappingProxyType as mappingproxy from types import MappingProxyType as mappingproxy
def exc_clear():
# exc_clear was removed in Python 3. The except statement automatically
# clears the exception.
pass
unicode = type(u'') unicode = type(u'')