fal 1.2.3__py3-none-any.whl → 1.2.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fal might be problematic. Click here for more details.

fal/_fal_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '1.2.3'
16
- __version_tuple__ = version_tuple = (1, 2, 3)
15
+ __version__ = version = '1.2.4'
16
+ __version_tuple__ = version_tuple = (1, 2, 4)
fal/app.py CHANGED
@@ -3,7 +3,9 @@ from __future__ import annotations
3
3
  import inspect
4
4
  import json
5
5
  import os
6
+ import queue
6
7
  import re
8
+ import threading
7
9
  import time
8
10
  import typing
9
11
  from contextlib import asynccontextmanager, contextmanager
@@ -72,17 +74,22 @@ def wrap_app(cls: type[App], **kwargs) -> fal.api.IsolatedFunction:
72
74
 
73
75
 
74
76
  class EndpointClient:
75
- def __init__(self, url, endpoint, signature):
77
+ def __init__(self, url, endpoint, signature, timeout: int | None = None):
76
78
  self.url = url
77
79
  self.endpoint = endpoint
78
80
  self.signature = signature
81
+ self.timeout = timeout
79
82
 
80
83
  annotations = endpoint.__annotations__ or {}
81
84
  self.return_type = annotations.get("return") or None
82
85
 
83
86
  def __call__(self, data):
84
87
  with httpx.Client() as client:
85
- resp = client.post(self.url + self.signature.path, json=dict(data))
88
+ resp = client.post(
89
+ self.url + self.signature.path,
90
+ json=data.dict() if hasattr(data, "dict") else dict(data),
91
+ timeout=self.timeout,
92
+ )
86
93
  resp.raise_for_status()
87
94
  resp_dict = resp.json()
88
95
 
@@ -93,7 +100,12 @@ class EndpointClient:
93
100
 
94
101
 
95
102
  class AppClient:
96
- def __init__(self, cls, url):
103
+ def __init__(
104
+ self,
105
+ cls,
106
+ url,
107
+ timeout: int | None = None,
108
+ ):
97
109
  self.url = url
98
110
  self.cls = cls
99
111
 
@@ -101,19 +113,38 @@ class AppClient:
101
113
  signature = getattr(endpoint, "route_signature", None)
102
114
  if signature is None:
103
115
  continue
104
-
105
- setattr(self, name, EndpointClient(self.url, endpoint, signature))
116
+ endpoint_client = EndpointClient(
117
+ self.url,
118
+ endpoint,
119
+ signature,
120
+ timeout=timeout,
121
+ )
122
+ setattr(self, name, endpoint_client)
106
123
 
107
124
  @classmethod
108
125
  @contextmanager
109
126
  def connect(cls, app_cls):
110
127
  app = wrap_app(app_cls)
111
128
  info = app.spawn()
129
+ _shutdown_event = threading.Event()
130
+
131
+ def _print_logs():
132
+ while not _shutdown_event.is_set():
133
+ try:
134
+ log = info.logs.get(timeout=0.1)
135
+ except queue.Empty:
136
+ continue
137
+ print(log)
138
+
139
+ _log_printer = threading.Thread(target=_print_logs, daemon=True)
140
+ _log_printer.start()
141
+
112
142
  try:
113
143
  with httpx.Client() as client:
114
144
  retries = 100
115
145
  while retries:
116
146
  resp = client.get(info.url + "/health")
147
+
117
148
  if resp.is_success:
118
149
  break
119
150
  elif resp.status_code != 500:
@@ -121,9 +152,12 @@ class AppClient:
121
152
  time.sleep(0.1)
122
153
  retries -= 1
123
154
 
124
- yield cls(app_cls, info.url)
155
+ client = cls(app_cls, info.url)
156
+ yield client
125
157
  finally:
126
158
  info.stream.cancel()
159
+ _shutdown_event.set()
160
+ _log_printer.join()
127
161
 
128
162
  def health(self):
129
163
  with httpx.Client() as client:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fal
3
- Version: 1.2.3
3
+ Version: 1.2.4
4
4
  Summary: fal is an easy-to-use Serverless Python Framework
5
5
  Author: Features & Labels <support@fal.ai>
6
6
  Requires-Python: >=3.8
@@ -1,10 +1,10 @@
1
1
  fal/__init__.py,sha256=wXs1G0gSc7ZK60-bHe-B2m0l_sA6TrFk4BxY0tMoLe8,784
2
2
  fal/__main__.py,sha256=MSmt_5Xg84uHqzTN38JwgseJK8rsJn_11A8WD99VtEo,61
3
- fal/_fal_version.py,sha256=VUBVzEBuW57s195P22MF-rLGH7GWx3G_z5nV-l_8MBE,411
3
+ fal/_fal_version.py,sha256=DFpsAdSrahcTSWRccxC8nEJpgcmby0LdmRoAddZy2zA,411
4
4
  fal/_serialization.py,sha256=rD2YiSa8iuzCaZohZwN_MPEB-PpSKbWRDeaIDpTEjyY,7653
5
5
  fal/_version.py,sha256=EBGqrknaf1WygENX-H4fBefLvHryvJBBGtVJetaB0NY,266
6
6
  fal/api.py,sha256=LAPl5Hf6ZWzEjv4lFUtsisWgrnXH_qNUHdJrEHT_A5Y,40602
7
- fal/app.py,sha256=9HJGu_64ArtW8W91BC0U4Etr2gA31LXaHgR6HzoOops,15903
7
+ fal/app.py,sha256=BM4lk6741Z0DKr3bYLLhEvRBuDkqZqo883LvPXjgOPQ,16812
8
8
  fal/apps.py,sha256=FrKmaAUo8U9vE_fcva0GQvk4sCrzaTEr62lGtu3Ld5M,6825
9
9
  fal/container.py,sha256=V7riyyq8AZGwEX9QaqRQDZyDN_bUKeRKV1OOZArXjL0,622
10
10
  fal/flags.py,sha256=oWN_eidSUOcE9wdPK_77si3A1fpgOC0UEERPsvNLIMc,842
@@ -122,8 +122,8 @@ openapi_fal_rest/models/workflow_node_type.py,sha256=-FzyeY2bxcNmizKbJI8joG7byRi
122
122
  openapi_fal_rest/models/workflow_schema.py,sha256=4K5gsv9u9pxx2ItkffoyHeNjBBYf6ur5bN4m_zePZNY,2019
123
123
  openapi_fal_rest/models/workflow_schema_input.py,sha256=2OkOXWHTNsCXHWS6EGDFzcJKkW5FIap-2gfO233EvZQ,1191
124
124
  openapi_fal_rest/models/workflow_schema_output.py,sha256=EblwSPAGfWfYVWw_WSSaBzQVju296is9o28rMBAd0mc,1196
125
- fal-1.2.3.dist-info/METADATA,sha256=tUsGGaLLvqfYpEePodE0fuc5nm_XSoYE7AWTrci2nEY,3805
126
- fal-1.2.3.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
127
- fal-1.2.3.dist-info/entry_points.txt,sha256=32zwTUC1U1E7nSTIGCoANQOQ3I7-qHG5wI6gsVz5pNU,37
128
- fal-1.2.3.dist-info/top_level.txt,sha256=r257X1L57oJL8_lM0tRrfGuXFwm66i1huwQygbpLmHw,21
129
- fal-1.2.3.dist-info/RECORD,,
125
+ fal-1.2.4.dist-info/METADATA,sha256=yCcxwr4BEx0DlAY2xi7FQzd_Qi-IChNr-aQ9QstwzUg,3805
126
+ fal-1.2.4.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
127
+ fal-1.2.4.dist-info/entry_points.txt,sha256=32zwTUC1U1E7nSTIGCoANQOQ3I7-qHG5wI6gsVz5pNU,37
128
+ fal-1.2.4.dist-info/top_level.txt,sha256=r257X1L57oJL8_lM0tRrfGuXFwm66i1huwQygbpLmHw,21
129
+ fal-1.2.4.dist-info/RECORD,,
File without changes