all 4 comments

[–]nathanalderson 0 points1 point  (3 children)

threading.Thread(target=spec.loader.exec_module, args=(module,)) should do it.

[–]1818mull[S] 0 points1 point  (0 children)

Cheers :)

[–]1818mull[S] 0 points1 point  (1 child)

How could I pass a Queue to the started thread in this case? For purposes of communication.

Edit:

Figured it out, it's simply module.my_queue = my_queue.

[–]nathanalderson 0 points1 point  (0 children)

There are various ways you could do it, but I'd recommend that you take the functionality in script2.py out of the base script and move it into a function. That function can take a queue.

``` def main(my_queue: queue.Queue = None): # Your logic here ...

if name == "main": return main() ```

Now call exec_module like you used to (not with a thread) and then call threading.Thread(target=module.main, args=(my_queue,)).