~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Andrew Bennetts
  • Date: 2010-04-08 09:24:42 UTC
  • mto: This revision was merged to the branch mainline in revision 5155.
  • Revision ID: andrew.bennetts@canonical.com-20100408092442-d3kqlxw88xgssrwh
Reset siginterrupt every time we handle a signal.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1365
1365
        False)`).  May be ignored if the feature is not available on this
1366
1366
        platform or Python version.
1367
1367
    """
1368
 
    old_handler = signal.signal(signum, handler)
 
1368
    try:
 
1369
        siginterrupt = signal.siginterrupt
 
1370
    except AttributeError:
 
1371
        # siginterrupt doesn't exist on this platform, or for this version
 
1372
        # of Python.
 
1373
        siginterrupt = lambda signum, flag: None
1369
1374
    if restart_syscall:
1370
 
        try:
1371
 
            siginterrupt = signal.siginterrupt
1372
 
        except AttributeError: # siginterrupt doesn't exist on this platform, or for this version of
1373
 
            # Python.
1374
 
            pass
1375
 
        else:
 
1375
        def sig_handler(*args):
 
1376
            # Python resets the siginterrupt flag when a signal is
 
1377
            # received.  Set it back the way we want it.
1376
1378
            siginterrupt(signum, False)
 
1379
            # Now run the handler function passed to set_signal_handler.
 
1380
            handler(*args)
 
1381
    else:
 
1382
        sig_handler = handler
 
1383
    old_handler = signal.signal(signum, sig_handler)
 
1384
    if restart_syscall:
 
1385
        siginterrupt(signum, False)
1377
1386
    return old_handler
1378
1387
 
1379
1388