Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4190 > unrolled thread

Re: Aborting Python from C code

Started byMiki Tebeka <miki.tebeka@gmail.com>
First post2011-04-30 01:08 -0700
Last post2011-05-04 13:16 -0400
Articles 4 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Re: Aborting Python from C code Miki Tebeka <miki.tebeka@gmail.com> - 2011-04-30 01:08 -0700
    Re: Aborting Python from C code Chris Angelico <rosuav@gmail.com> - 2011-04-30 18:17 +1000
    Re: Aborting Python from C code Chris Angelico <rosuav@gmail.com> - 2011-05-04 19:02 +1000
    newbie needs help with cookielib "Sells, Fred" <fred.sells@adventistcare.org> - 2011-05-04 13:16 -0400

#4190 — Re: Aborting Python from C code

FromMiki Tebeka <miki.tebeka@gmail.com>
Date2011-04-30 01:08 -0700
SubjectRe: Aborting Python from C code
Message-ID<c63e7579-16d1-4bfa-8486-8ab791343dba@glegroupsg2000goo.googlegroups.com>
> In our sandboxed Python environment, I would like to be able to
> trigger an abort of the currently-running Python script (from a signal
> handler or another thread).
There's os.abort

[toc] | [next] | [standalone]


#4192

FromChris Angelico <rosuav@gmail.com>
Date2011-04-30 18:17 +1000
Message-ID<mailman.1015.1304151439.9059.python-list@python.org>
In reply to#4190
On Sat, Apr 30, 2011 at 6:08 PM, Miki Tebeka <miki.tebeka@gmail.com> wrote:
>> In our sandboxed Python environment, I would like to be able to
>> trigger an abort of the currently-running Python script (from a signal
>> handler or another thread).
> There's os.abort

That core dumps the process; what I want is to force the
PyRun_StringFlags to return. Normally PyErr_SetInterrupt will do
exactly this (within a few instructions is fine), but the Python
script is able to prevent that from happening, which I don't like.

Chris Angelico

[toc] | [prev] | [next] | [standalone]


#4603

FromChris Angelico <rosuav@gmail.com>
Date2011-05-04 19:02 +1000
Message-ID<mailman.1144.1304499763.9059.python-list@python.org>
In reply to#4190
On Sat, Apr 30, 2011 at 7:29 PM, Dylan Evans <dylan@contentfree.info> wrote:
> I think i see what you are trying to do but it depends on the environment
> and your goals.
> Generally i think you need to separate your code by forking (or perhaps you
> have already done that?),
> then you can run a check to see if the process died as expected. I don't
> know though, this not much
> information to go on, but if you are running untrusted code then you need to
> be able to isolate and kill it.

Well, I've gone with a slight variant on this. If the Python script
doesn't terminate in a timely manner, the process will be killed with
a longjmp straight from the signal handler (the setjmp having been
done long long ago back when the process initialized itself). So
Py_Finalize() will be called, but no other Python-related functions
_at all_, and the process promptly terminates. I'm assuming that
Python will flush out all its state on process termination (that is,
it doesn't hang onto any system-global resources).

Thanks for the advice!

Chris Angelico

[toc] | [prev] | [next] | [standalone]


#4633 — newbie needs help with cookielib

From"Sells, Fred" <fred.sells@adventistcare.org>
Date2011-05-04 13:16 -0400
Subjectnewbie needs help with cookielib
Message-ID<mailman.1159.1304529452.9059.python-list@python.org>
In reply to#4190
I'm using Python 2.4 and 2.7 for different apps.  I'm happy with a
solution for either one.

I've got to talk to a url that uses a session cookie.  I only need to
set this when I'm developing/debugging so I don't need a robust
production solution and I'm somewhat confused by the docs on cookielib.
I can use urllib2 without cookielib just fine, but need the cookie to
add some security.

I'm normally using Firefox 4.0 to login to the server and get the
cookie.  After that I need some way to set the same cookie in my python
script.  I can do this by editing my code, since I only need it while
defeloping from my test W7 box.


I was hoping to find something like

...set_cookie('mycookiename', 'myvalue', 'mydomain.org')

I've googled this most of the morning and found everything but what I
need, or I just don't understand the basic concept.  Any pointers would
be greatly appreciated.  One of my false starts looks like this. But I
get a 

...
  File "C:\alltools\python26\lib\urllib2.py", line 518, in
http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Access Deinied

def test1():
    cj = cookielib.MozillaCookieJar()
    cj.load('C:/Users/myname/Desktop/cookies.txt')
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    r = opener.open("http://daffyduck.mydomain.org/wsgi/myapp.wsgi")   
    print r.read() 
    return

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web