2222import os
2323import sys
2424import time
25- import resource
25+ # 'resource' is a Unix specific module.
26+ has_resource_module = True
27+ try :
28+ import resource
29+ except ImportError :
30+ has_resource_module = False
2631import socket
2732import traceback
2833
@@ -268,9 +273,9 @@ def main(infile, outfile):
268273
269274 # set up memory limits
270275 memory_limit_mb = int (os .environ .get ('PYSPARK_EXECUTOR_MEMORY_MB' , "-1" ))
271- total_memory = resource . RLIMIT_AS
272- try :
273- if memory_limit_mb > 0 :
276+ if memory_limit_mb > 0 and has_resource_module :
277+ total_memory = resource . RLIMIT_AS
278+ try :
274279 (soft_limit , hard_limit ) = resource .getrlimit (total_memory )
275280 msg = "Current mem limits: {0} of max {1}\n " .format (soft_limit , hard_limit )
276281 print (msg , file = sys .stderr )
@@ -283,9 +288,9 @@ def main(infile, outfile):
283288 print (msg , file = sys .stderr )
284289 resource .setrlimit (total_memory , (new_limit , new_limit ))
285290
286- except (resource .error , OSError , ValueError ) as e :
287- # not all systems support resource limits, so warn instead of failing
288- print ("WARN: Failed to set memory limit: {0}\n " .format (e ), file = sys .stderr )
291+ except (resource .error , OSError , ValueError ) as e :
292+ # not all systems support resource limits, so warn instead of failing
293+ print ("WARN: Failed to set memory limit: {0}\n " .format (e ), file = sys .stderr )
289294
290295 # initialize global state
291296 taskContext = None
0 commit comments