File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
tornasole_core/access_layer Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 3
3
from tornasole_core .utils import is_s3 , get_logger
4
4
import logging
5
5
import time
6
- import nest_asyncio
7
- nest_asyncio .apply ()
8
6
9
7
8
+ def check_notebook ():
9
+ # try to see if we are in an iPython environment and import nest_asyncio appropriately
10
+ #
11
+ try :
12
+ get_ipython ()
13
+ import nest_asyncio
14
+ nest_asyncio .apply ()
15
+ except NameError :
16
+ pass
17
+
10
18
# Must be created for ANY file read request, whether from S3 or Local
11
19
# If you wish to download entire file, leave length as None and start as 0.
12
20
# If length is None, start must be 0.
@@ -38,7 +46,10 @@ class S3Handler:
38
46
# For debug flag, first set PYTHONASYNCIODEBUG=1 in terminal.
39
47
# This provides terminal output revealing details about the AsyncIO calls and timings that may be useful.
40
48
# num_retries: the number of times to retry a download or connection before logging an exception.
49
+
41
50
def __init__ (self , num_retries = 5 , debug = False ):
51
+ # if you are creating an s3handler object in jupyter, ensure the nest_asyncio is applied
52
+ check_notebook ()
42
53
self .loop = asyncio .get_event_loop ()
43
54
self .client = aioboto3 .client ('s3' , loop = self .loop )
44
55
self .num_retries = num_retries
You can’t perform that action at this time.
0 commit comments