CoCalc
Sharedsupport / 2016-12-26-103443-alarm.sagewsOpen in CoCalc

Examples for support purposes...

alarm?
File: 
Docstring :
Raise an "AlarmInterrupt" exception in a given number of seconds.
This is useful for automatically interrupting long computations and
can be trapped using exception handling.

Use "cancel_alarm()" to cancel a previously scheduled alarm.

INPUT:

* "seconds" -- positive number, may be floating point

OUTPUT: None

EXAMPLES:

   >>> from cysignals.alarm import alarm, AlarmInterrupt
   >>> from time import sleep
   >>> try:
   ...     alarm(0.5)
   ...     sleep(2)
   ... except AlarmInterrupt:
   ...     print("alarm!")
   alarm!
   >>> alarm(0)
   Traceback (most recent call last):
   ...
   ValueError: alarm() time must be positive
fork?
File: /projects/sage/sage-7.3/local/lib/python2.7/site-packages/smc_sagews/sage_salvus.py
Signature : fork()
Docstring :
The %fork block decorator evaluates its code in a forked subprocess
that does not block the main process.

You may still use the @fork function decorator from Sage, as usual,
to run a function in a subprocess.  Type "sage.all.fork?" to see
the help for the @fork decorator.

WARNING: This is highly experimental and possibly flaky. Use with
caution.

All (picklelable) global variables that are set in the forked
subprocess are set in the parent when the forked subprocess
terminates.  However, the forked subprocess has no other side
effects, except what it might do to file handles and the
filesystem.

To see currently running forked subprocesses, type fork.children(),
which returns a dictionary {pid:execute_uuid}. To kill a given
subprocess and stop the cell waiting for input, type
fork.kill(pid).  This is currently the only way to stop code
running in %fork cells.

TODO/WARNING: The subprocesses spawned by fork are not killed if
the parent process is killed first!

NOTE: All pexpect interfaces are reset in the child process.