Signal.alarm() Hugging Face uyumluluğu sağlandı
Browse files- Main thread kontrolü eklendi
- Signal kullanılamadığında sadece requests timeout kullanılıyor
- Hugging Face'de çalışması için gerekli düzeltmeler yapıldı
app.py
CHANGED
@@ -34,15 +34,22 @@ def get_warehouse_stock(product_name):
|
|
34 |
"""B2B API'den mağaza stok bilgilerini çek - Optimize edilmiş versiyon"""
|
35 |
try:
|
36 |
import re
|
37 |
-
import signal
|
38 |
|
39 |
-
#
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
try:
|
48 |
warehouse_url = 'https://video.trek-turkey.com/bizimhesap-warehouse-xml-b2b-api-v2.php'
|
@@ -75,7 +82,7 @@ def get_warehouse_stock(product_name):
|
|
75 |
search_words = search_name.split()
|
76 |
|
77 |
print(f"DEBUG - Searching for: {product_name}")
|
78 |
-
print(f"DEBUG - Normalized: {search_name}")
|
79 |
print(f"DEBUG - Search words: {search_words}")
|
80 |
|
81 |
# Search using new B2B API structure
|
@@ -201,15 +208,21 @@ def get_warehouse_stock(product_name):
|
|
201 |
return ["Hiçbir mağazada mevcut değil"]
|
202 |
|
203 |
except TimeoutError:
|
204 |
-
|
|
|
|
|
|
|
|
|
205 |
print("Warehouse API timeout - skipping")
|
206 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
|
208 |
except Exception as e:
|
209 |
-
try:
|
210 |
-
signal.alarm(0)
|
211 |
-
except:
|
212 |
-
pass
|
213 |
print(f"Mağaza stok bilgisi çekme hatası: {e}")
|
214 |
return None
|
215 |
|
|
|
34 |
"""B2B API'den mağaza stok bilgilerini çek - Optimize edilmiş versiyon"""
|
35 |
try:
|
36 |
import re
|
|
|
37 |
|
38 |
+
# Hugging Face'de signal çalışmadığı için try-except kullan
|
39 |
+
use_signal = False
|
40 |
+
try:
|
41 |
+
import signal
|
42 |
+
import threading
|
43 |
+
# Test if we're in main thread
|
44 |
+
if threading.current_thread() is threading.main_thread():
|
45 |
+
def timeout_handler(signum, frame):
|
46 |
+
raise TimeoutError("Warehouse API timeout")
|
47 |
+
signal.signal(signal.SIGALRM, timeout_handler)
|
48 |
+
signal.alarm(8)
|
49 |
+
use_signal = True
|
50 |
+
except Exception as e:
|
51 |
+
print(f"Signal not available: {e}")
|
52 |
+
use_signal = False
|
53 |
|
54 |
try:
|
55 |
warehouse_url = 'https://video.trek-turkey.com/bizimhesap-warehouse-xml-b2b-api-v2.php'
|
|
|
82 |
search_words = search_name.split()
|
83 |
|
84 |
print(f"DEBUG - Searching for: {product_name}")
|
85 |
+
print(f"DEBUG - Normalized (gen kept): {search_name}")
|
86 |
print(f"DEBUG - Search words: {search_words}")
|
87 |
|
88 |
# Search using new B2B API structure
|
|
|
208 |
return ["Hiçbir mağazada mevcut değil"]
|
209 |
|
210 |
except TimeoutError:
|
211 |
+
if use_signal:
|
212 |
+
try:
|
213 |
+
signal.alarm(0)
|
214 |
+
except:
|
215 |
+
pass
|
216 |
print("Warehouse API timeout - skipping")
|
217 |
return None
|
218 |
+
finally:
|
219 |
+
if use_signal:
|
220 |
+
try:
|
221 |
+
signal.alarm(0)
|
222 |
+
except:
|
223 |
+
pass
|
224 |
|
225 |
except Exception as e:
|
|
|
|
|
|
|
|
|
226 |
print(f"Mağaza stok bilgisi çekme hatası: {e}")
|
227 |
return None
|
228 |
|