Update soybean_dataset.py
Browse files- soybean_dataset.py +10 -3
soybean_dataset.py
CHANGED
@@ -35,7 +35,7 @@ from numpy import asarray
|
|
35 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
36 |
import requests
|
37 |
import asyncio
|
38 |
-
|
39 |
import logging
|
40 |
|
41 |
|
@@ -121,9 +121,16 @@ class SoybeanDataset(datasets.GeneratorBasedBuilder):
|
|
121 |
datasets.SplitGenerator(
|
122 |
name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["valid"]}),
|
123 |
]
|
124 |
-
|
|
|
|
|
125 |
def wrapped(*args, **kwargs):
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
127 |
return wrapped
|
128 |
|
129 |
@background
|
|
|
35 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
36 |
import requests
|
37 |
import asyncio
|
38 |
+
from functools import wraps
|
39 |
import logging
|
40 |
|
41 |
|
|
|
121 |
datasets.SplitGenerator(
|
122 |
name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["valid"]}),
|
123 |
]
|
124 |
+
|
125 |
+
def background(f):
|
126 |
+
@wraps(f)
|
127 |
def wrapped(*args, **kwargs):
|
128 |
+
loop = asyncio.get_event_loop()
|
129 |
+
if loop.is_running():
|
130 |
+
# If the loop is already running, we can't use run_in_executor directly.
|
131 |
+
# You would need to ensure this is handled correctly depending on your application's architecture.
|
132 |
+
raise RuntimeError("Asyncio loop already running")
|
133 |
+
return loop.run_in_executor(None, f, *args, **kwargs)
|
134 |
return wrapped
|
135 |
|
136 |
@background
|