[mod_python] All spawned threads in Restricted Exection Mode

Mike Solomon mike at mrlventures.com
Sat Apr 9 17:06:02 EDT 2005


I too see this problem and it's driving me bananas.

I've got Apache 2.0.53, mod_python 3.1.4, python 2.4 installed under 
SuSE 9.1. My servlet code and apache config are exactly the same as 
Alan's (to minimize potential setup variables.)

My specific problem is that pickling causes this unmarshal error:

(it doesn't seem to matter what i pickle, or if i use cPickle vs pickle)

Traceback (most recent call last):
   File "/home/msolomon/test/zclient/client.py", line 10, in
   RuntimeError: cannot unmarshal code objects in restricted execution 
mode

That line looks like this:
  9:  obj = None
10:  in_a_pickle = pickle.dumps(obj, 2)


Now here is a very strange observation - this exception does not occur 
if I put the contents of client.py into threadtest.py - it only happens 
when the code is imported.

I'm not sure why threads appear to be executing in restricted mode - 
but if that is the problem, I guess I'd like to know how to turn that 
off.  Despite stumbling onto a few occurrences of this problem, I have 
yet to see a solution posted anywhere.

If either of you gentlemen have any additional insight, I would 
appreciate it.

------

My servlet looks like this (threadtest.py):

import mod_python
from zclient.client import Client

def handler(req):
   c = Client()
   req.write(str(c.perform()))
   return mod_python.apache.OK


This is zclient/client.py:

import cPickle as pickle
import threading, traceback

class Client:
   def thread_op(self, results):
     try:
       obj = None
       in_a_pickle = pickle.dumps(obj, 2)
       results.append('ok')
     except Exception, e:
       results.extend(traceback.format_exc().split('\n'))

   def perform(self):
     results = []
     t = threading.Thread(target=self.thread_op, args=(results,))
     t.start()
     t.join()
     return str(results)



More information about the Mod_python mailing list