gem-graph-server/oldsrc/localthread.py

62 lines
2.6 KiB
Python
Raw Normal View History

#=----------------------------------------------------------------------------=#
# Local computing threads related functions #
# #
# Copyright © 2021 The Gem-graph Project #
# #
# This file is part of gem-graph. #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU Affero General Public License as #
# published by the Free Software Foundation, either version 3 of the #
# License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU Affero General Public License for more details. #
# #
# You should have received a copy of the GNU Affero General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
#=----------------------------------------------------------------------------=#
import random
import multiprocessing
class CurrentlyComputing(Exception):
pass
class SuccessfulOperation(Exception):
pass
class FailedOperation(Exception):
pass
## Local Threads
class LocalComputingUnit(multiprocessing.Process):
def __init__(self, id, shared_memory, address, orientation, transitions):
multiprocessing.Process.__init__(self)
self.id = id
self.address = address
self.orientation = orientation
self.transitions = transitions
self.namespace = shared_memory.Namespace()
self.namespace.returncode = CurrentlyComputing()
def run(self):
try:
# Actual code
print("Thread local n°{} parle depuis {} !".format(self.id, self.address))
L = [random.randint(0,3000) for x in range(random.randint(0, 300))]
for i in range(10000000):
sum(range(100))
self.namespace.returncode = SuccessfulOperation()
except Exception as exception:
self.namespace.returncode = exception