Ask Your Question
3

Can I pause a computation rather than aborting it? (Interrupt Command)

asked 14 years ago

ccanonc gravatar image

updated 10 years ago

FrédéricC gravatar image

Can I pause a computation rather than aborting it?

Sometimes I don't want to discard work by raising an exception. It would be nice if I could just pause execution ad hoc.

Preview: (hide)

Comments

Harder: It would be nice if I could inspect the paused state too.

ccanonc gravatar imageccanonc ( 14 years ago )

2 Answers

Sort by » oldest newest most voted
7

answered 14 years ago

William Stein gravatar image

You can find the PID of the working process by typing os.getpid() in the worksheet. So to do what you want now, try the following:

  1. In the first worksheet (the one you may want to pause), type os.getpid() and note the PID.
  2. Start something that will take a long time (e.g., factor(2^997-1)) going in the first worksheet.
  3. In a second worksheet, type import signal; os.kill(that pid above, signal.SIGSTOP). The first worksheet will appear to be running, but will not use any CPU resources, as you can confirm with top on the server.
  4. Now in the second worksheet, type os.kill(that pid above, signal.SIGCONT). You will see in top that the Python process associated with the first worksheet is back and burning resources.

The point of the above exercise is that it illustrates that a pause feature could fully work. To really do this right, one would need to add something to the Sage Notebook itself, e.g., modify the sagenb spkg. This would involve some GUI design choices, etc.

Preview: (hide)
link

Comments

Does the worksheet process do the spawning then (is it the parent)? If so, the PID could be displayed by default for worksheets (since a person might not call os.getpid() first, by forgetting). Or does twisted spawn the processes? Neither? In any case it would be a cool project.

ccanonc gravatar imageccanonc ( 14 years ago )

A related project might be accounting for spawned time. I've noticed that "%time" sometimes puts almost everything in Wall time, which strictly speaking is correct, but not as interesting as a 3-way breakdown. A more difficult project perhaps.

ccanonc gravatar imageccanonc ( 14 years ago )

Twisted spawns the worksheet process. It can determine the PID of that process.

William Stein gravatar imageWilliam Stein ( 14 years ago )
3

answered 14 years ago

Mike Hansen gravatar image

There currently isn't any way to pause a computation in the notebook. The only way I can think of the implement such a thing would be to send a SIGTSTP signal to the worker process, but I do not know how the pexpect interface to that process would behave.

Preview: (hide)
link

Comments

How would I find the proper parent process to send a cascade of SIGTSTPs?

ccanonc gravatar imageccanonc ( 14 years ago )

Mike -- this is a very good idea. I think it would be likely to work. ccanonc -- as you probably know, on the command line you can just hit "control-Z" to pause, and "fg" to start again.

William Stein gravatar imageWilliam Stein ( 14 years ago )

When I say "likely to work", I mean "with a bunch of work, eventually it could be made to work".

William Stein gravatar imageWilliam Stein ( 14 years ago )

Mike: I wish I could mark both answers as favorite, but I don't think I can. I think it would be a good askbot enhancement: to have a max threshold. I'll comment on that Q&A thread.

ccanonc gravatar imageccanonc ( 14 years ago )

I thought that William's was better than mine :-)

Mike Hansen gravatar imageMike Hansen ( 14 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 14 years ago

Seen: 6,151 times

Last updated: Aug 24 '10