
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Python SDK for the go-server distributed task scheduling system. This SDK provides both client and worker libraries for interacting with the go-server scheduler.
Important: Before using this Python SDK, you must have the go-server scheduler running. The scheduler is the core component that manages and distributes tasks to workers.
Clone the go-server repository:
git clone https://github.com/go-enols/go-server.git
cd go-server
Build and run the scheduler:
# Build the project
go build -o scheduler ./go-sdk/examples/scheduler/scheduler
# Run the scheduler (default port: 8080)
./scheduler
For detailed configuration options and advanced setup, please refer to the go-server documentation.
Note: The scheduler must be running and accessible before you can use any of the SDK features. All examples in this documentation assume the scheduler is running on http://localhost:8080
.
install from requirements.txt:
pip install -r requirements.txt
install from source:
python setup.py install
from python_sdk.scheduler import SchedulerClient
# Create a client
client = SchedulerClient("http://localhost:8080")
# Execute a task synchronously
result = client.execute_sync("add", {"a": 1, "b": 2}, timeout=30.0)
print(f"Result: {result.result}") # Output: Result: 3
# Execute a task asynchronously
response = client.execute("add", {"a": 5, "b": 3})
task_id = response.task_id
# Get the result later
result = client.get_result(task_id)
print(f"Async result: {result.result}") # Output: Async result: 8
from python_sdk.worker import Worker, Config
import time
# Define your methods
def add_numbers(params):
"""Add two numbers"""
return params["a"] + params["b"]
def multiply_numbers(params):
"""Multiply two numbers"""
return params["a"] * params["b"]
def long_running_task(params):
"""Simulate a long-running task"""
time.sleep(params.get("duration", 5))
return {"status": "completed", "message": "Task finished"}
# Create worker configuration
config = Config(
scheduler_url="http://localhost:8080",
worker_group="math_workers",
max_retry=3,
ping_interval=30
)
# Create and configure worker
worker = Worker(config)
# Register methods with documentation
worker.register_method(
"add",
add_numbers,
"Add two numbers",
"Parameters: {\"a\": number, \"b\": number}",
"Returns: number"
)
worker.register_method(
"multiply",
multiply_numbers,
"Multiply two numbers",
"Parameters: {\"a\": number, \"b\": number}",
"Returns: number"
)
worker.register_method(
"long_task",
long_running_task,
"Execute a long-running task",
"Parameters: {\"duration\": number (optional, default: 5)}",
"Returns: {\"status\": string, \"message\": string}"
)
# Start the worker
try:
worker.start()
print("Worker started. Press Ctrl+C to stop.")
# Keep the worker running
import signal
import sys
def signal_handler(sig, frame):
print("\nStopping worker...")
worker.stop()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
signal.pause()
except Exception as e:
print(f"Error starting worker: {e}")
worker.stop()
For quick one-off calls, you can use the simple call
function:
from python_sdk.worker import call
# Simple synchronous call
result = call("http://localhost:8080", "add", {"a": 1, "b": 2})
print(f"Result: {result}") # Output: Result: 3
# Call with type hint
result: int = call("http://localhost:8080", "add", {"a": 1, "b": 2}, int)
# Async call
from python_sdk.worker import call_async, get_result
task_id = call_async("http://localhost:8080", "long_task", {"duration": 10})
print(f"Task submitted: {task_id}")
# Get result later
result = get_result("http://localhost:8080", task_id)
print(f"Task result: {result}")
For more robust operation, use the retry client:
from python_sdk.scheduler import RetryClient
# Create retry client with custom settings
client = RetryClient(
base_url="http://localhost:8080",
max_retries=5,
retry_delay=2.0,
timeout=30
)
# Execute with automatic retry
result = client.execute_with_retry("add", {"a": 1, "b": 2})
print(f"Result: {result.result}")
# Synchronous execution with retry
result = client.execute_sync_with_retry("multiply", {"a": 3, "b": 4}, timeout=60.0)
print(f"Result: {result.result}")
execute(method, params)
: Execute a task asynchronouslyget_result(task_id)
: Get result for a task (with polling)execute_sync(method, params, timeout)
: Execute a task synchronouslyexecute_with_retry(method, params)
: Execute with automatic retryexecute_sync_with_retry(method, params, timeout)
: Synchronous execution with retryregister_method(name, handler, *docs)
: Register a method handlerstart()
: Start the workerstop()
: Stop the workerconfig = Config(
scheduler_url="http://localhost:8080", # Scheduler URL
worker_group="my_workers", # Worker group name
max_retry=3, # Connection retry attempts
ping_interval=30 # Heartbeat interval (seconds)
)
The SDK provides comprehensive error handling:
from python_sdk.scheduler import SchedulerClient
import requests
client = SchedulerClient("http://localhost:8080")
try:
result = client.execute_sync("nonexistent_method", {})
except requests.RequestException as e:
print(f"Network error: {e}")
except ValueError as e:
print(f"Invalid response: {e}")
except RuntimeError as e:
print(f"Task execution error: {e}")
except TimeoutError as e:
print(f"Timeout: {e}")
pip install -e ".[dev]"
pytest
black python_sdk/
flake8 python_sdk/
mypy python_sdk/
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
FAQs
Python SDK for go-server distributed task scheduling system
We found that go-server-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.