except IOError as fnf:
    print("webservers.txt file was not found\n")
    print("Please make sure the file is in the globaltrace directory\n")

# Create a directory for each country's  traceroute experiments
for c in countries:
    current_server = c.split(',')
    c_name = current_server[0]
    if c_name == sender:
        print("Ignoring current sender in webserver list\n")
    else:
        subprocess.call(["mkdir", c_name])
        subprocess.call(["mv", c_name, directory])

# Start the timer
start = mytimer()

# Repeat the experiment for 8 hours.
# Script still responds to process signals, i.e CTRL + C, D, etc.
# Alternatively, the subprocess can be killed by removing it from ps list.
while (mytimer() - start) <= 28800:
    for c in countries:
        current_server = c.split(',')
        c_name = current_server[0]
        web_server = current_server[1]
        if c_name != sender:
            try:
                country_code = ''.join(c_name[:3])
                print("Running traceroute to %s next\n" % c_name)
                filename = subprocess.check_output(
                    ["./FileCreation", country_code], universal_newlines=True)
#!/usr/bin/python3.4

# Sends pathload packets to receiver every 30 minutes
# Sender version
# Code help on timer obtained at https://stackoverflow.com/questions/36952245/subprocess-timeout-failure
# Author Gloire Rubambiza
# Version 07/02/2017

import subprocess
from time import monotonic as mytimer
import time

start = mytimer()

# Wait until 8 hours have gone by
while ( mytimer() - start) <= 288000:
	try:
	    return_code = subprocess.call(["./pathload_snd"])
	except TimeoutExpired:
	    print("The child process is done running pathload\n")
     
     # Check the return code before going to sleep
	if return_code != 0:
	    print("Return code error, child process failed")
     
	time.sleep(60*4)


Exemple #3
0
#! /usr/bin/env python3

import time
from time import time as mytimer
import random

input("Press enter to start")
wait_time = random.randint(1, 6)
time.sleep(wait_time)
start_time = mytimer()

input("Press enter to stop")
end_time = mytimer()

print("started at", time.strftime("%X", start_time))
print("stopped at", time.strftime("%X", end_time))
print("reaction was {}".format(end_time - start_time))