Michal Wilinski
Posts: 2
Joined: Wed Feb 22, 2017 11:16 pm

Missions running at the same time ?

Wed Feb 22, 2017 11:25 pm

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.

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Missions running at the same time ?

Sat Feb 25, 2017 7:47 pm

Hi there, sorry for the slow reply. I was in the Netherlands for a meeting with ESA and got stuck over there because of Storm Dorris.

Try this code, it should be fairly self explanatory:

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")
Output should look like this:

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
Good luck!

Michal Wilinski
Posts: 2
Joined: Wed Feb 22, 2017 11:16 pm

Re: Missions running at the same time ?

Sat Feb 25, 2017 8:43 pm

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.

mattmiller
Posts: 2063
Joined: Thu Feb 05, 2015 11:25 pm

Re: Missions running at the same time ?

Sat Feb 25, 2017 9:08 pm

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

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1662
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Missions running at the same time ?

Sun Feb 26, 2017 7:50 pm

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.
So the judging criteria is listed on this page: https://astro-pi.org/proxima/
  • Scientific value
  • Creativity and originality
  • Feasibility of the missions within the ISS environment
  • Code readability and quality
  • Overall rigour, clarity, and comprehensiveness
So yes what you want to do with the data will be considered under Scientific value. So perhaps give a mock up example of what you expect to get?
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
This just makes it safe for running in either python2 or python3.
In python2 the module is called thread, but in python3 it's called _thread.

mattmiller
Posts: 2063
Joined: Thu Feb 05, 2015 11:25 pm

Re: Missions running at the same time ?

Sun Feb 26, 2017 9:02 pm

In python2 the module is called thread, but in python3 it's called _thread.
Got it- I'm a Python2ister so I didn't understand how thread could be missing! :)

Return to “Astro Pi”