First set_time_limit (0); will make your script run forever, so timeout should not be a problem. The second call to any * exec in PHP does NOT use PATH by default (it may depend on the configuration), so your script will exit without providing any information about the problem, and quite often it turns out that it cannot find programs, in this case python. Therefore, change it to:
shell_exec("/full/path/to/python /full/path/to/my/script");
If your python script runs on it on its own without problems, then this is most likely a problem. As far as memory is concerned, I'm sure PHP will not use the same memory as python. Therefore, if it uses 300 MB of PHP, it should remain at the default level (say, 1 MB) and just wait for shell_exec to finish.
source share