Skip to content

Commit dfc0c8f

Browse files
authored
Merge pull request #576 from cr1901/no-resource
Gate POSIX-only signals and resource module to only run on POSIX Pyth…
2 parents d70830a + 0caa628 commit dfc0c8f

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

backends/smt2/smtio.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
#
1818

1919
import sys, re, os, signal
20-
import resource, subprocess
20+
import subprocess
21+
if os.name == "posix":
22+
import resource
2123
from copy import deepcopy
2224
from select import select
2325
from time import time
@@ -27,12 +29,13 @@
2729

2830
# This is needed so that the recursive SMT2 S-expression parser
2931
# does not run out of stack frames when parsing large expressions
30-
smtio_reclimit = 64 * 1024
31-
smtio_stacksize = 128 * 1024 * 1024
32-
if sys.getrecursionlimit() < smtio_reclimit:
33-
sys.setrecursionlimit(smtio_reclimit)
34-
if resource.getrlimit(resource.RLIMIT_STACK)[0] < smtio_stacksize:
35-
resource.setrlimit(resource.RLIMIT_STACK, (smtio_stacksize, -1))
32+
if os.name == "posix":
33+
smtio_reclimit = 64 * 1024
34+
smtio_stacksize = 128 * 1024 * 1024
35+
if sys.getrecursionlimit() < smtio_reclimit:
36+
sys.setrecursionlimit(smtio_reclimit)
37+
if resource.getrlimit(resource.RLIMIT_STACK)[0] < smtio_stacksize:
38+
resource.setrlimit(resource.RLIMIT_STACK, (smtio_stacksize, -1))
3639

3740

3841
# currently running solvers (so we can kill them)
@@ -51,8 +54,9 @@ def force_shutdown(signum, frame):
5154
os.kill(p.pid, signal.SIGTERM)
5255
sys.exit(1)
5356

57+
if os.name == "posix":
58+
signal.signal(signal.SIGHUP, force_shutdown)
5459
signal.signal(signal.SIGINT, force_shutdown)
55-
signal.signal(signal.SIGHUP, force_shutdown)
5660
signal.signal(signal.SIGTERM, force_shutdown)
5761

5862
def except_hook(exctype, value, traceback):
@@ -1053,4 +1057,3 @@ def set_time(self, t):
10531057
print("b0 %s" % self.nets[path][0], file=self.f)
10541058
else:
10551059
print("b1 %s" % self.nets[path][0], file=self.f)
1056-

0 commit comments

Comments
 (0)