Say that you have a singleton to play with (which means that the only way to initialize that to original state is to restart the whole script) and you want to do a specific tasks multiple times on this and get the returned objects. Are there any ways I can do this without disk I/O? I know I can do that with subprocess.check_output()
like How to spawn another process and capture output in python? and file I/O or piping stdio
, but are there any cleaner solutions as simple as same-process communications (Edit: I mean, result = foo()
)?
#the singleton
def foo():
crash_when_got_run_twice()
result = something_fancy()
return result
#the runner
def bar(times):
for i in range(times):
result = magic() # run foo()
aggregate_result(result)
return aggregated_result()
What do you think you can do in magic()
?