11"""Module for launching MAPDL locally."""
22from glob import glob
3- import time
4- import subprocess
53import re
64import warnings
75import os
86import appdirs
97import tempfile
108import socket
11- import pexpect
129
1310from pyansys .misc import is_float , random_string
1411from pyansys .errors import LockFileException , VersionError
@@ -209,114 +206,6 @@ def check_lock_file(path, jobname, override):
209206 'running at "%s"' % path )
210207
211208
212-
213- def launch_corba (exec_file = None , run_location = None , jobname = None , nproc = None ,
214- additional_switches = '' , start_timeout = 60 ):
215- """Start MAPDL in AAS mode
216-
217-
218- Notes
219- -----
220- The CORBA interface is likely to fail on computers with multiple
221- network adapters. The ANSYS RPC isn't smart enough to determine
222- the right adapter and will likely try to communicate on the wrong
223- IP.
224- """
225- # Using stored parameters so launch command can be run from a
226- # cached state (when launching the GUI)
227-
228- # can't run /BATCH in windows, so we trick it using "-b" and
229- # provide a dummy input file
230- if os .name == 'nt' :
231- # must be a random filename to avoid conflicts with other
232- # potential instances
233- tmp_file = '%s.inp' % random_string (10 )
234- with open (os .path .join (run_location , tmp_file ), 'w' ) as f :
235- f .write ('FINISH' )
236- additional_switches += ' -b -i %s -o out.txt' % tmp_file
237-
238- # command must include "aas" flag to start MAPDL server
239- command = '"%s" -aas -j %s -np %d %s' % (exec_file ,
240- jobname ,
241- nproc ,
242- additional_switches )
243-
244- # if os.name == 'nt': # required after v190
245- # command = 'START /B "MAPDL" %s' % command
246-
247- # remove any broadcast files
248- broadcast_file = os .path .join (run_location , 'mapdl_broadcasts.txt' )
249- if os .path .isfile (broadcast_file ):
250- os .remove (broadcast_file )
251-
252- # windows 7 won't run this
253- # if os.name == 'nt' and platform.release() == '7':
254- # cwd = os.getcwd()
255- # os.chdir(run_location)
256- # os.system('START /B "MAPDL" %s' % command)
257- # os.chdir(cwd)
258- # else:
259- subprocess .Popen (command , shell = True ,
260- cwd = run_location ,
261- stdin = subprocess .DEVNULL ,
262- stdout = subprocess .DEVNULL ,
263- stderr = subprocess .DEVNULL )
264-
265- # listen for broadcast file
266- telapsed = 0
267- tstart = time .time ()
268- started_rpc = False
269- while telapsed < start_timeout and not started_rpc :
270- try :
271- if os .path .isfile (broadcast_file ):
272- broadcast = open (broadcast_file ).read ()
273- # see if connection to RPC has been made
274- rpc_txt = 'visited:collaborativecosolverunitior-set:'
275- started_rpc = rpc_txt in broadcast
276-
277- time .sleep (0.1 )
278- telapsed = time .time () - tstart
279-
280- except KeyboardInterrupt :
281- raise KeyboardInterrupt
282-
283- # exit if timed out
284- if not started_rpc :
285- err_str = 'Unable to start ANSYS within %.1f seconds' % start_timeout
286- if os .path .isfile (broadcast_file ):
287- broadcast = open (broadcast_file ).read ()
288- err_str += '\n \n Last broadcast:\n %s' % broadcast
289- raise TimeoutError (err_str )
290-
291- # return CORBA key
292- keyfile = os .path .join (run_location , 'aaS_MapdlId.txt' )
293- return open (keyfile ).read ()
294-
295-
296- def launch_pexpect (exec_file = None , run_location = None , jobname = None , nproc = None ,
297- additional_switches = '' , start_timeout = 60 ):
298- """Launch MAPDL as a pexpect process.
299-
300- Limited to only a linux instance
301- """
302- command = '%s -j %s -np %d %s' % (exec_file , jobname , nproc ,
303- additional_switches )
304- process = pexpect .spawn (command , cwd = run_location )
305- process .delaybeforesend = None
306-
307- try :
308- index = process .expect (['BEGIN:' , 'CONTINUE' ],
309- timeout = start_timeout )
310- except : # capture failure
311- raise RuntimeError (process .before .decode ('utf-8' ))
312-
313- if index : # received ... press enter to continue
314- process .sendline ('' )
315- process .expect ('BEGIN:' , timeout = start_timeout )
316-
317- return process
318-
319-
320209def launch_mapdl (exec_file = None , run_location = None , mode = None , jobname = 'file' ,
321210 nproc = 2 , override = False , loglevel = 'INFO' ,
322211 additional_switches = '' , start_timeout = 120 ,
@@ -632,16 +521,12 @@ def launch_mapdl(exec_file=None, run_location=None, mode=None, jobname='file',
632521
633522 if mode == 'console' :
634523 from pyansys .mapdl_console import MapdlConsole
635- process = launch_pexpect (** start_parm )
636- return MapdlConsole (process , loglevel = loglevel ,
637- log_apdl = log_apdl , ** start_parm )
524+ return MapdlConsole (loglevel = loglevel , log_apdl = log_apdl , ** start_parm )
638525 elif mode == 'corba' :
639526 from pyansys .mapdl_corba import MapdlCorba
640- corba_key = launch_corba (** start_parm )
641- return MapdlCorba (corba_key , loglevel = loglevel ,
642- log_apdl = log_apdl ,
643- log_broadcast = kwargs .get ('log_broadcast' , False ),
644- ** start_parm )
527+ return MapdlCorba (loglevel = loglevel , log_apdl = log_apdl ,
528+ log_broadcast = kwargs .get ('log_broadcast' ,
529+ False ), ** start_parm )
645530 else :
646531 raise ValueError ('Invalid mode %s' % mode )
647532
@@ -663,12 +548,6 @@ def check_mode(mode, version):
663548 if mode == 'corba' :
664549 if version < 170 :
665550 raise VersionError ('CORBA AAS mode requires MAPDL v17.0 or newer.' )
666- # elif version > 20.1 and os.name == 'nt':
667- # raise ValueError('CORBA AAS mode on Windows requires MAPDL 2020R1'
668- # ' or earlier.')
669- # elif version >= 20.0 and os.name == 'posix':
670- # raise ValueError('CORBA AAS mode on Linux requires MAPDL 2019R3'
671- # ' or earlier.')
672551
673552 elif mode == 'console' and is_win :
674553 raise ValueError ('Console mode requires Linux' )
0 commit comments