Skip to main content

PyPI

🙅 Zerofun

Remote function calls for array data using ZMQ.

NOTE: Zerofun has been rewritten without ZMQ using raw Python sockets and is now called Portal. You can keep using Zerofun but it will receive no further updates. To suppress the message, install zerofun==2.3.1. To upgrade, run pip install portal and visit github.com/danijar/portal. The API is nearly the same but allows for more flexible function arguments and offers higher performance and reliability.

Overview

Zerofun provides a Server that you can bind functions to and a Client that can call the messages and receive their results. The function inputs and results are both flat dicts of Numpy arrays. The data is sent efficiently without serialization to maximize throughput.

Installation

pip install zerofun

Example

This example runs the server and client in the same Python program using subprocesses, but they could also be separate Python scripts running on different machines.

def server():
  import zerofun
  server = zerofun.Server('tcp://*:2222')
  server.bind('add', lambda data: {'result': data['foo'] + data['bar']})
  server.bind('msg', lambda data: print('Message from client:', data['msg']))
  server.run()

def client():
  import zerofun
  client = zerofun.Client('tcp://localhost:2222')
  client.connect()
  future = client.add({'foo': 1, 'bar': 1})
  result = future.result()
  print(result)  # {'result': 2}
  client.msg({'msg': 'Hello World'})

if __name__ == '__main__':
  import zerofun
  server_proc = zerofun.Process(server, start=True)
  client_proc = zerofun.Process(client, start=True)
  client_proc.join()
  server_proc.terminate()

Features

Several productivity and performance features are available:

  • Request batching: The server can batch requests together so that the user function receives a dict of stacked arrays and the function result will be split and sent back to the corresponding clients.
  • Multithreading: Servers can use a thread pool to process multiple requests in parallel. Optionally, each function can also request its own thread pool to allow functions to block (e.g. for rate limiting) without blocking other functions.
  • Async clients: Clients can send multiple overlapping requests and wait on the results when needed using Future objects. The maximum number of inflight requests can be limited to avoid requests building up when the server is slower than the client.
  • Error handling: Exceptions raised in server functions are reported to the client and raised in future.result() or, if the user did not store the future object, on the next request. Worker exception can also be reraised in the server application using server.check().
  • Heartbeating: Clients can send ping requests when they have not received a result from the server for a while, allowing to wait for results that take a long time to compute without assuming connection loss.
  • Concurrency: Thread and Process implementations with exception forwarding that can be forcefully terminated by the parent, which Python threads do not natively support. Stoppable threads and processes are also available for coorperative shutdown.
  • GIL load reduction: The ProcServer behaves just like the normal Server but uses a background process to batch requests and fan out results, substantially reducing GIL load for the server workers in the main process.

Questions

Please open a GitHub issue for each question. Over time, we will add common questions to the README.

Release files for zerofun 2.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zerofun 2.4.0
File Size Uploaded
zerofun-2.4.0.tar.gz 18.5 kB Details

Release files / zerofun-2.4.0.tar.gz

Download URL zerofun-2.4.0.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ebfc69a7d741d4ec5c54426058a2403d7deba3c20cce8414d88ec055a1089d00
BLAKE2b-256 checksum
How to use checksums
63331fb0585e0ad8fc60b09fa6bb0b47300df6ce04db24aedb81793391d6a93e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.9

Release history Release notifications | RSS feed

This release

2.4.0 This release

1 release file

2.3.1

1 release file

2.3.0

1 release file

2.2.0

1 release file

2.1.6

1 release file

2.1.5

1 release file

2.1.4

1 release file

2.1.3

1 release file

2.1.2

1 release file

2.1.1

1 release file

2.1.0

1 release file

2.0.6

1 release file

2.0.5

1 release file

2.0.4

1 release file

2.0.3

1 release file

2.0.2

1 release file

2.0.1

1 release file

2.0.0

1 release file

1.2.0

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page