Skip to content

Commit 346ad97

Browse files
committed
Updated package v4.16
1 parent f45c2ec commit 346ad97

File tree

4 files changed

+72
-5
lines changed

4 files changed

+72
-5
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
All notable changes to LocalLab will be documented in this file.
44

5+
## 0.4.16 - 2025-03-11
6+
7+
### Fixed
8+
9+
- Fixed critical error: "'Config' object has no attribute 'server_class'"
10+
- Implemented custom startup method that doesn't rely on config.server_class
11+
- Fixed import issues in Google Colab by properly exposing start_server in **init**.py
12+
- Enhanced compatibility with different versions of uvicorn
13+
- Improved server initialization for more reliable startup
14+
- Added direct TCPServer initialization for better compatibility
15+
- Implemented fallback mechanisms for TCPServer import to handle different uvicorn versions
16+
- Added multiple import paths for TCPServer to ensure compatibility across all environments
17+
- Enhanced error handling during server initialization
18+
- Improved Google Colab integration with better import structure
19+
- Added custom main_loop implementation with robust error handling
20+
- Implemented graceful shutdown mechanism for all server components
21+
- Enhanced server stability with improved error recovery
22+
523
## 0.4.15 - 2025-03-11
624

725
### Fixed

locallab/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
LocalLab - A lightweight AI inference server for running LLMs locally
33
"""
44

5-
__version__ = "0.4.15"
5+
__version__ = "0.4.16"
66

77
# Only import what's necessary initially, lazy-load the rest
88
from .logger import get_logger
99

10+
# Explicitly expose start_server for direct import
11+
from .server import start_server, cli
12+
1013
# Other imports will be lazy-loaded when needed
1114

1215
# Don't import these by default to speed up CLI startup

locallab/server.py

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,49 @@ async def startup(self, sockets=None):
220220
if self.should_exit:
221221
return
222222

223+
# Custom implementation that doesn't rely on config.server_class
223224
if sockets is not None:
224225
self.servers = []
225226
for socket in sockets:
226-
server = await self.config.server_class(config=self.config, server=self)
227+
# Use TCPServer directly instead of relying on config.server_class
228+
try:
229+
# Try the newer location first
230+
from uvicorn.server import TCPServer
231+
server = TCPServer(config=self.config)
232+
except (ImportError, AttributeError):
233+
try:
234+
# Try the older location
235+
from uvicorn.protocols.http.h11_impl import TCPServer
236+
server = TCPServer(config=self.config)
237+
except (ImportError, AttributeError):
238+
# Last resort - use a simple server implementation
239+
logger.warning("Could not import TCPServer - using simple server implementation")
240+
from uvicorn.protocols.http.auto import AutoHTTPProtocol
241+
server = uvicorn.Server(config=self.config)
242+
243+
server.server = self # Set the server reference
227244
await server.start()
228245
self.servers.append(server)
229246
else:
230-
self.servers = [await self.config.server_class(config=self.config, server=self)]
231-
await self.servers[0].start()
247+
# Use TCPServer directly instead of relying on config.server_class
248+
try:
249+
# Try the newer location first
250+
from uvicorn.server import TCPServer
251+
server = TCPServer(config=self.config)
252+
except (ImportError, AttributeError):
253+
try:
254+
# Try the older location
255+
from uvicorn.protocols.http.h11_impl import TCPServer
256+
server = TCPServer(config=self.config)
257+
except (ImportError, AttributeError):
258+
# Last resort - use a simple server implementation
259+
logger.warning("Could not import TCPServer - using simple server implementation")
260+
from uvicorn.protocols.http.auto import AutoHTTPProtocol
261+
server = uvicorn.Server(config=self.config)
262+
263+
server.server = self # Set the server reference
264+
await server.start()
265+
self.servers = [server]
232266

233267
if self.lifespan is not None:
234268
try:
@@ -240,6 +274,18 @@ async def startup(self, sockets=None):
240274
self.lifespan = NoopLifespan(self.config.app)
241275
logger.warning("Replaced failed lifespan with NoopLifespan")
242276

277+
async def main_loop(self):
278+
"""Custom main loop implementation with error handling."""
279+
try:
280+
# Use asyncio.sleep to keep the server running
281+
while not self.should_exit:
282+
await asyncio.sleep(0.1)
283+
except Exception as e:
284+
logger.error(f"Error in main loop: {str(e)}")
285+
logger.debug(f"Main loop error details: {traceback.format_exc()}")
286+
# Set should_exit to True to initiate shutdown
287+
self.should_exit = True
288+
243289
async def shutdown(self, sockets=None):
244290
"""Override the shutdown method to add error handling for lifespan shutdown."""
245291
if self.servers:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name="locallab",
8-
version="0.4.15",
8+
version="0.4.16",
99
packages=find_packages(include=["locallab", "locallab.*"]),
1010
install_requires=[
1111
"fastapi>=0.95.0,<1.0.0",

0 commit comments

Comments
 (0)