Hi all,
I am very exciting about the sub-interpreters ... but I do not like some parts ...
Consider the following code:
```python
import _xxsubinterpreters as interpreters
import threading
import textwrap as tw
import marshal
if __name__ == '__main__':
# Create a sub-interpreter
interpid = interpreters.create()
# If you had a function that generated some data
arry = list(range(0,100))
# Create a channel
channel_id = interpreters.channel_create()
# Pre-populate the interpreter with a module
interpreters.run_string(interpid, "import marshal; import _xxsubinterpreters as interpreters")
# Define a
def run(interpid, channel_id):
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Still is run in thread which is use GIL !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
interpreters.run_string(interpid,
tw.dedent("""
arry_raw = interpreters.channel_recv(channel_id)
arry = marshal.loads(arry_raw)
result = [1,2,3,4,5] # where you would do some calculating
result_raw = marshal.dumps(result)
interpreters.channel_send(channel_id, result_raw)
"""),
shared=dict(
channel_id=channel_id
),
)
inp = marshal.dumps(arry)
interpreters.channel_send(channel_id, inp)
# Run inside a thread
t = threading.Thread(target=run, args=(interpid, channel_id))
t.start()
# Sub interpreter will process. Feel free to do anything else now.
output = interpreters.channel_recv(channel_id)
interpreters.channel_release(channel_id)
output_arry = marshal.loads(output)
print(output_arry)
```
Add some `async` execution of `interpreters.run_string_async` and other async functions !!
Also regarding the threads ... I think it is better to make `threading.Thread` as green `Thread` !!
I know, I know, `Thread` is not possible due to `sync io` ... But we can to change underling `api` from `sync io` to `async io` !!
User will notice nothing, but performance will be increased mush more !!
Consider the following execution of `threading.Thread` in Python:
```
gil_lock.acquire()
for green_thread in green_threads:
thread.execute()
gil_lock.release()
```
If we implement in such way we will be able to reduce resource used in system, but performance would be the same !!
Sub-Interpreter would be the something like Workers in JavaScript, but much more flexible !!
What we will have at the end:
1) `threading.Thread` is a green thread that do not consume a lot of resources but still useful !!
2) Real parallelizm is done within sub-interpreters like workers in JavaScript, but much more flexible
Say what do you think ?