On this page:
6.1 The Big Picture
6.2 Reference
initialize
post-initialize
add-initialization-thunk
diagnostics

6 Initialization of the Python Interpreter

6.1 The Big Picture

In order to use the functions in pyffi you need to start a Python interpreter. The call (initialize) does just that. A standard approach would be to make the call in your "main" module of your program.

That the Python interpreter isn’t available until the main module has been instantiated leads to a few complications. The problem is the interpreter instance is not available when the modules required by "main" is instantiated.

As an example: The module pyffi/numpy contains bindings for NumPy. If the main module looks like this:

#lang racket

(require pyffi pyffi/numpy)

(initialize)

Then pyffi/numpy is instantiated before the interpreter is started. This means pyffi/numpy can’t inspect the Python module numpy to get the function signatures it needs.

To solve this problem pyffi/numpy registers a number of initialization thunks to be run after the interpreter has started. The function post-initialize runs these initialization thunks.

To sum up, the typical main module for a program that uses pyffi starts:

#lang racket

(require pyffi pyffi/numpy)

(initialize)

(post-initialize)

6.2 Reference

procedure

(initialize)  void?

Starts a Python interpreter using libpython.

The precise steps taken are:

procedure

(post-initialize)  void?

Run initialization thunks that needs a running Python instance.

procedure

(add-initialization-thunk thunk)  void?

  thunk : thunk?
Add a thunk to be run by post-initialize.

procedure

(diagnostics)  void?

Print important Python paths.