Prefetch python module before first use

Hello,
I would like to prefetch a python module before the first use to avoid the latency when the script is loaded the fist time.

Include the script in the blend file, load the modules from there. You may have to attach it to an empty via the logic bricks if you plan linking.

Thank you CaptainAndrew, but i should have not explain the problem correctly : i’ve already done that, but, when a script is first use, there is a very little time of latency : this would be a time to read and precompile the script (a sort of prefetech), despite of the fact that there is no real compilation because it’s a script.
The first time the script is called, i loose 15 FPS, and after that, no problem. I would like to know if there is a way to prefetch the script whitout having of using it.

Moved from “Game Engine Resources” to “Game Engine Support and Discussion”

Hmm. Could you trigger the script for the first time as soon as the scene loads up? For example you could enable the “Level” mode on Sensor. This would trigger the script at start.

This “delay” is a result of:
A) compiling of the module (.py -> .pyc)
B) loading of the compiled byte code

A) will not happen if the code was compiled before (and the .pyc is newer)
B) will happen all the time (I just wonder how large your code is that you notice a delay).

As Mperonen already wrote you can load/initialize the module right after game start, getting the delay at frame 1. Trigger with an always (no pulses). Level is not necessary (as it is frame 1).