Skip to content

Commit

Permalink
count CPUs
Browse files Browse the repository at this point in the history
  • Loading branch information
gcb committed Sep 5, 2015
1 parent 25afd32 commit 066495d
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions multiprocessing/queue/gcbtest.py
Expand Up @@ -20,6 +20,17 @@
class GCBTest():
# mpq_main - the main queue of the program. this is what the controller (here) will use to know what is going on
def __init__(self):
try:
cpus = MP.cpu_count()
if DEBUG_MULTI_PROCESS:
print( 'CONTROL: found %d CPUs' % cpus )
#<if
except NotImplementedError:
if DEBUG_MULTI_PROCESS:
print( 'CONTROL: cannot detect number of CPUs. assuming one.' )
cpus = 1
#<if
#<except
self.mpq_main = MP.Queue() # where we, the controller, receive messages
self.mpq_ui = MP.Queue() # messages to the children...
self.mpq_fs = MP.Queue()
Expand All @@ -33,40 +44,48 @@ def __init__(self):
self.mpt_net.start();
# when all is started up, kick our main loop
return self.check_queue()
#<def

x = 1
def check_queue(self):
self.x += 1
if self.x == 5:
self.mpq_ui.put('draw A')
#
#<if
if self.x == 10:
self.mpq_fs.put('test 1')
self.mpq_fs.put('test 2')
#
#<if
if DEBUG_MULTI_PROCESS:
print( 'CONTROL: check' )
#<if
if not self.mpq_main.empty(): #work around retarded Queue vs multiprocess namespace for exceptions
msg = self.mpq_main.get(0) # todo handle a list in case we have arguments. or maybe another queue for data?
# Check contents of message and do what it says
if DEBUG_MULTI_PROCESS:
print( 'CONTROL: ', msg )
#<if
if msg == 'UI quit':
self.do_polite_quit()
#<if
else:
pass
#<if
#
# TODO: check if all threads are still up
sleep(.5)
return self.check_queue()
#<def

def do_polite_quit(self):
# TODO: be polite
self.mpt_ui.terminate()
self.mpt_fs.terminate()
self.mpt_net.terminate()
sys.exit()

#<def
#<class

if __name__ == '__main__':
theclass = GCBTest()
#<if

0 comments on commit 066495d

Please sign in to comment.