- Catch UserInterruptException launched from

PythonPolicy in Scheduler, but it cheerfully 
segfaults python...


git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@464 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
tchernobog 2006-02-26 23:38:25 +00:00
parent 8c39173c2f
commit 0a6b34d6ab
3 changed files with 112 additions and 85 deletions

View File

@ -156,12 +156,13 @@ PythonPolicy::get_time_slice() const throw(UserInterruptException) {
void void
PythonPolicy::wait_unlock() const throw(UserInterruptException) PythonPolicy::wait_unlock() const throw(UserInterruptException)
{ {
PyThreadState *_save; PyThreadState* _save;
int i = 0; // We give the sort_queue() three seconds max time, then... int i = 0; // We give the sort_queue() three seconds max time, then...
// we shot it stone dead! Bang. // we shot it stone dead! Bang.
bool still_locked; bool still_locked;
do { do
{
Py_UNBLOCK_THREADS; Py_UNBLOCK_THREADS;
usleep(25000); // hack'a'ton! magggggiccc nummmbeeerrrrrs!! usleep(25000); // hack'a'ton! magggggiccc nummmbeeerrrrrs!!
Py_BLOCK_THREADS; Py_BLOCK_THREADS;
@ -171,9 +172,12 @@ PythonPolicy::wait_unlock() const throw(UserInterruptException)
Py_DECREF(retval); Py_DECREF(retval);
if(i++ > 120) if(i++ > 120)
{
throw UserInterruptException("User-defined policy is " throw UserInterruptException("User-defined policy is "
"taking too long to terminate."); "taking too long to terminate.");
} while(still_locked); }
}
while(still_locked);
// What we should really do here: // What we should really do here:

View File

@ -21,6 +21,9 @@
#include "policy.hh" #include "policy.hh"
#include "scheduler.hh" #include "scheduler.hh"
#include "policy_manager.hh" #include "policy_manager.hh"
#include "user_interrupt_exception.hh"
#include <iostream>
using namespace std; using namespace std;
using namespace sgpem; using namespace sgpem;
using namespace memory; using namespace memory;
@ -79,6 +82,8 @@ Scheduler::get_policy()
void void
Scheduler::step_forward() Scheduler::step_forward()
{ {
try
{
Policy& policy = get_policy(); Policy& policy = get_policy();
History& h = History::get_instance(); History& h = History::get_instance();
@ -183,9 +188,25 @@ Scheduler::step_forward()
_ready_queue.add_at_bottom(*initial->get_item_at(i)); _ready_queue.add_at_bottom(*initial->get_item_at(i));
cout << "\n"; cout << "\n";
/* for (uint i = 0; i < _ready_queue.size(); i++) /* for (uint i = 0; i < _ready_queue.size(); i++)
cout << " " << _ready_queue.get_item_at(i)->get_schedulable()->get_name() cout << " " << _ready_queue.get_item_at(i)->get_schedulable()->get_name()
<<"_" << _ready_queue.get_item_at(i)->get_state(); <<"_" << _ready_queue.get_item_at(i)->get_state();
*/ */
h.enqueue_slice(_ready_queue); h.enqueue_slice(_ready_queue);
}
catch( UserInterruptException e )
{
// FIXME : Naive.
cerr << "Exception: " << e.what() << endl;
// Errrrr.... you won't like this:
_policy_manager.init();
// https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1165761&group_id=5470
// maybe it's that??? oh, damn.
// or maybe not. see http://www.python.org/doc/2.4.2/api/initialization.html
// Tell:
// - the user that the policy sucks
// - SimulationController that everything stopped
}
} }

View File

@ -15,6 +15,8 @@ class fcfs(Policy) :
return -1 return -1
def sort_queue(self, event, queue): def sort_queue(self, event, queue):
#while True:
# pass
cmpf = lambda a, b: \ cmpf = lambda a, b: \
a.get_schedulable().get_arrival_time() < \ a.get_schedulable().get_arrival_time() < \
b.get_schedulable().get_arrival_time() b.get_schedulable().get_arrival_time()