Skip to content

Instantly share code, notes, and snippets.

@bencord0
Created October 9, 2025 15:29
Show Gist options
  • Select an option

  • Save bencord0/240ae1df9daac501c238dd9d19ba4d35 to your computer and use it in GitHub Desktop.

Select an option

Save bencord0/240ae1df9daac501c238dd9d19ba4d35 to your computer and use it in GitHub Desktop.
Multicore Python using concurrent.interpreters
from concurrent import interpreters
interps = [
interpreters.create(),
interpreters.create(),
interpreters.create(),
]
def fib(n):
a, b = 0, 1
for _ in range(n):
a, b = b, a + b
def submain():
interp = interpreters.get_current()
ident = interp.id
print(f'Starting interpreter: {ident}')
fib(ident * 999999)
def main():
threads = []
for interp in interps:
t = interp.call_in_thread(submain)
threads.append(t)
print('All spawned')
for t in threads:
t.join()
print(f'{t.name} Joined')
print('All joined')
for interp in interps:
interp.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment