Hello, so I have a question about multitasking in Python.
What do I need to do to make 2 mission codes (primary and secondary) run at the same time ? I've tried to use multithreading but it failed.

Code: Select all
import time
from signal import pause
try:
import thread
except ImportError:
import _thread as thread
running = True
def mission1(data):
global running
while running:
print("doing mission 1")
time.sleep(0.5)
def mission2(data):
global running
while running:
print("doing mission 2")
time.sleep(1)
mission1data = None
mission2data = None
thread.start_new_thread(mission1, (mission1data,))
thread.start_new_thread(mission2, (mission2data,))
try:
pause()
except KeyboardInterrupt:
running = False
print("bye")
Code: Select all
doing mission 2
doing mission 1
doing mission 1
doing mission 2
doing mission 1
doing mission 1
doing mission 2
doing mission 1
doing mission 1
doing mission 2
Code: Select all
try:
import thread
except ImportError:
import _thread as thread
So the judging criteria is listed on this page: https://astro-pi.org/proxima/Michal Wilinski wrote:Hi,
Thanks, it's finally working!
I have another question (sorry for offtopic). What will the judges consider when rating our project? Only code is important or what we will do with data after program results return from the ISS ? Example: we're planning to make climate chart but it is only possible when we get the results from the station. Is the chart considered in rating process? Sorry for English, but I'm not native speaker.
This just makes it safe for running in either python2 or python3.mattmiller wrote:OT
I'm intrigued as to this snippet - whats the philosophy behind it?
Is there some chance that the thread module doesn't exist?Code: Select all
try: import thread except ImportError: import _thread as thread
Got it- I'm a Python2ister so I didn't understand how thread could be missing!In python2 the module is called thread, but in python3 it's called _thread.