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

View File

@ -21,6 +21,9 @@
#include "policy.hh"
#include "scheduler.hh"
#include "policy_manager.hh"
#include "user_interrupt_exception.hh"
#include <iostream>
using namespace std;
using namespace sgpem;
using namespace memory;
@ -79,6 +82,8 @@ Scheduler::get_policy()
void
Scheduler::step_forward()
{
try
{
Policy& policy = get_policy();
History& h = History::get_instance();
@ -183,9 +188,25 @@ Scheduler::step_forward()
_ready_queue.add_at_bottom(*initial->get_item_at(i));
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()
<<"_" << _ready_queue.get_item_at(i)->get_state();
*/
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
def sort_queue(self, event, queue):
#while True:
# pass
cmpf = lambda a, b: \
a.get_schedulable().get_arrival_time() < \
b.get_schedulable().get_arrival_time()