Alternative to DATA on a notebook with separate worker accounts?

41 views
Skip to first unread message

Nils Bruin

unread,
Aug 2, 2012, 7:58:44 PM8/2/12
to sage-devel
I noticed that on more "public" notebooks, where the sage worker
processes run under a different UID than the notebook server, there is
a problem that "DATA" is generally not writable by the worker. That
means that, for instance for profiling, the command

cProfile.run(cmd, DATA + "profdata")

will fail. Are there reasonable alternatives to DATA as a writable
location for the worker that is also conveniently accessible from
other cells?

William Stein

unread,
Aug 2, 2012, 10:43:42 PM8/2/12
to sage-...@googlegroups.com
If the data is ephemeral, you could use the tempfile module.

> --
> --
> To post to this group, send an email to sage-...@googlegroups.com
> To unsubscribe from this group, send an email to sage-devel+...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/sage-devel
> URL: http://www.sagemath.org
>
>
>
>

--
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

Nils Bruin

unread,
Aug 3, 2012, 1:29:29 AM8/3/12
to sage-devel
On Aug 2, 7:43 pm, William Stein <wst...@gmail.com> wrote:
> If the data is ephemeral, you could use the tempfile module.

Thanks! excellent suggestion. For future reference:

If you do:

import tempfile
F=tempfile.NamedTemporaryFile()

then you have a usable (existing) filename F.name

Beware that once the reference to F gets lost, the file gets deleted.
Pass "delete=false" to NamedTemporaryFile to avoid that (but then you
need to clean up yourself). An even dirtier version is

filename=tempfile.NamedTemporaryFile().name

which does give you a filename that is all likelyhood is usable and
probably nonexistent, but leaves you with a nasty racing condition
(see tempfile docs).

Nils Bruin

unread,
Aug 3, 2012, 1:42:10 AM8/3/12
to sage-devel
On Aug 2, 4:58 pm, I wrote:
> cProfile.run(cmd, DATA + "profdata")

For future reference, my next command was going to be

s=pstats.Stats(DATA +"profdata")

in which case one can avoid using the temporary file altogether by
doing

import cProfile,pstats
s=pstats.Stats(cProfile.Profile().run(cmd))

It makes you wonder why cProfile.run has its current interface ...

Timo Kluck

unread,
Aug 10, 2012, 5:08:49 AM8/10/12
to sage-...@googlegroups.com

Op vrijdag 3 augustus 2012 07:42:10 UTC+2 schreef Nils Bruin het volgende:
in which case one can avoid using the temporary file altogether by
doing

import cProfile,pstats
s=pstats.Stats(cProfile.Profile().run(cmd))

It makes you wonder why cProfile.run has its current interface ...

Hope you don't mind my asking this unrelated question, but since you are interested in profiling in the notebook, would you mind reviewing my patch implementing %prun in the notebook? The ticket is
http://trac.sagemath.org/5814
 

Keshav Kini

unread,
Aug 10, 2012, 5:11:26 AM8/10/12
to sage-...@googlegroups.com
Timo Kluck <tkl...@gmail.com> writes:
> Hope you don't mind my asking this unrelated question, but since you
> are interested in profiling in the notebook, would you mind reviewing
> my patch implementing %prun in the notebook? The ticket is
> http://trac.sagemath.org/5814

Reviewers, please look here instead:
http://github.com/sagemath/sagenb/pull/91

-Keshav

----
Join us in #sagemath on irc.freenode.net !

Reply all
Reply to author
Forward
0 new messages