Package epyunit :: Package debug :: Module pydevrdc
[hide private]
[frames] | no frames]

Source Code for Module epyunit.debug.pydevrdc

  1  # -*- coding: utf-8 -*- 
  2  """Support for the automation of cross-process remote debugging with PyDev and Eclipse. 
  3   
  4  The module provides helpers for the debugging with the PyDev in the Eclipse IDE. 
  5  This includes utilities for the **cross-process debugging** by **Remote-Debugging**. 
  6  The PyDevRDC module provides processes started outside the PyDev environment, 
  7  as well as processes under control of PyDev. 
  8   
  9  In case the module epyunit.debug.checkRDbg is not yet loaded, this is done 
 10  and the provided parameters are passed through to the initial call:: 
 11   
 12      epyunit.debug.checkRDbg.checkAndRemoveRDbgOptions() 
 13   
 14  See 'http://pydev.org/manual_adv_remote_debugger.html' 
 15   
 16  The following parameters modify the control flow: 
 17   
 18  * Module Variables: 
 19   
 20      * **epyunit.debug.pydevrdc.PYDEVD**: 
 21          Provides a pre-allocated controller object 
 22          for remote debugging by PyDev as Eclipse plugin. 
 23          Could be extended by custom instances as required. 
 24          Just requires a simple import statement and could 
 25          thereafter be controlled by parameters. 
 26   
 27  * Environment Variables: 
 28   
 29      * **PYDEVDSCAN**: 
 30          The start directory for search on 'pydevd.py'. 
 31          If not set, the default is:: 
 32   
 33            px = $HOME/eclipse/eclipse 
 34            px = os.path.abspath(px) 
 35            px = os.path.realname(px) 
 36            px = os.path.dirname(px) 
 37            px = os.path.normpath(px) 
 38   
 39   
 40  """ 
 41  from __future__ import absolute_import 
 42  from tests.libs.checkRDbg import rdbg_root 
 43   
 44  __author__ = 'Arno-Can Uestuensoez' 
 45  __license__ = "Artistic-License-2.0 + Forced-Fairplay-Constraints" 
 46  __copyright__ = "Copyright (C) 2010-2016 Arno-Can Uestuensoez @Ingenieurbuero Arno-Can Uestuensoez" 
 47  __version__ = '0.2.1' 
 48  __uuid__='9de52399-7752-4633-9fdc-66c87a9200b8' 
 49   
 50  __docformat__ = "restructuredtext en" 
 51   
 52  import os,sys 
 53  version = '{0}.{1}'.format(*sys.version_info[:2]) 
 54  if not version in ('2.6', '2.7',): # pragma: no cover 
 55      raise Exception("Requires Python-2.6.* or higher") 
 56   
 57  from types import NoneType 
 58  import glob 
 59   
 60  from filesysobjects.FileSysObjects import findRelPathInSearchPath,clearPath,addPathToSearchPath,getHome 
 61  from epyunit.debug.checkRDbg import _pderd_inTestMode_suppress_init, _dbg_self, _dbg_unit,\ 
 62      _verbose 
 63  from epyunit.debug.checkRDbg import _rdbgroot,_rdbgroot_default, _rdbgsub_default,_rdbgenv 
 64  import epyunit.debug.checkRDbg 
 65   
 66  PYDEVD = None 
 67   
 68  # 
 69  # check whether epyunit.debug.checkRDbg has been called before, if not do it now 
 70  # 
 71  if not epyunit.debug.checkRDbg._rdbgoptions: 
 72      epyunit.debug.checkRDbg.checkAndRemoveRDbgOptions() 
 73   
74 -class PyDevRDCException(Exception):
75 pass
76
77 -class PyDevRDCLoadException(PyDevRDCException):
78 """Failed load of 'pydevd.py'. 79 """
80 - def __init__(self):
81 ret="\n" 82 ret+="\n" 83 ret+="Cannot load module 'pydevd':\n" 84 ret+="\n" 85 ret+=" Set PYTHONPATH, or use more call parameters.\n" 86 ret+=" See PyDev manual for path reference:\n" 87 ret+=" 'eclipse/plugins/org.python.pydev_x.x.x/pysrc/pydevd.py'\n" 88 ret+="\n" 89 super(PyDevRDCException,self).__init__(ret)
90
91 -class PyDevRDCServerException(PyDevRDCException):
92 """Debug server of PyDev is not running - cannot be reached. 93 """
94 - def __init__(self):
95 ret="\n" 96 ret+="\n" 97 ret+="Cannot connect to debug server, start it using Eclipse menu:\n" 98 ret+="\n" 99 ret+=" In Debug-Perspective: 'PyDev -> Start Debug Server'\n" 100 ret+="\n" 101 super(PyDevRDCException,self).__init__(ret)
102
103 -class PyDevRDC(object):
104 """Provides automation for remote debugging of external Python process with PyDev. 105 106 This particularly provides a prepared environment for 107 cross-process debugging by 'pydevd'. 108 """ 109 110 _initok=False 111 """Controls whether to be initialized.""" 112 113 defaultargs={} 114 115 dgbargs_default = { 116 'host': 'localhost', # host(None) 117 'stdoutToServer': True, # stdoutToServer(False) 118 'stderrToServer': True, # stderrToServer(False) 119 'port': 5678, # port(5678) 120 'suspend': False, # suspend(True) : 121 'trace_only_current_thread': True, # trace_only_current_thread(False) 122 'overwrite_prev_trace': False, # 'ignore' == overwrite_prev_trace(False) 123 'patch_multiprocessing': True, # patch_multiprocessing(False), 124 } 125 """ 126 Final default configuration arguments for a debug controller, see pydevd.settrace. 127 """ 128 129 pydevd_glob = "org.python.pydev_[0-9]*.[0-9]*.[0-9]*/pysrc/pydevd.py" 130 """ 131 Subpath glob pattern of PyDev plugin. 132 """ 133 134 eclipse_glob = _rdbgroot 135 """ 136 Subpath glob pattern for any eclipse based PyDev installation. 137 """ 138 139 _clrargs = {'abs':True, 'non-existent':True,'split':True,'redundant':True,'shrink':True,'normpath':True} 140 """ 141 Args for 'filesysobjects.clearPath' 142 """ 143
144 - def __init__(self,**kargs):
145 """Create a control stub for a remote debugger. 146 147 Search and load 'pydevd' for cross-process remote debugging. 148 149 Args: 150 **kargs: 151 152 debug: 153 154 Debug RDBG itself, developer output. 155 156 label=<name>: 157 158 An optional label for identifying the currrent instance. 159 The label could be provided as debugging flag. 160 161 remotedebug: 162 163 Switches remote debugging support On/Off. Dependent of 164 this parameter an internal call of startRemoteDebugExt 165 is performed and a new instance initialized. 166 167 rootforscan: 168 169 Directory path for the module 'pydevd.py', else defaults 170 of 'scanEclipseForPydevd'. 171 172 fpname: 173 174 The file path name of the main file for the current 175 process, default:=callname. 176 177 label: 178 179 The label identifying the current process, default:=callname. 180 181 noargv: 182 183 Suppresses argv processing completely for the previous 184 arguments. The testflags are still processed. 185 186 rdbg: 187 188 Same as '--rdbg', for additional processing see 'noargv'. 189 190 rdbgsrv: 191 192 Same as '--rdbg'srv, for additional processing see 'noargv'. 193 194 rdbgforward: 195 196 Same as '--rdbg-forward', for additional processing 197 see 'noargv'. 198 199 rdbgroot: 200 201 Same as '--rdbg-root', for additional processing see 'noargv'. 202 203 rdbgsub: 204 205 Same as '--rdbg-sub', for additional processing see 'noargv'. 206 207 208 testflags: 209 210 Flags to force specific behaviour - mostly faulty - 211 in order to test the module itself. So, **do not use** 212 these if you do not know what these actually do. 213 214 These partially fail, but provide a sufficient 215 part of the control flow for the aspect of interest. 216 217 ignorePydevd: 218 219 Debugging the initial bootstrap of an simulated 220 external process. Ignores present loaded debug 221 support. For debugging of the debug support. 222 223 ignorePydevdSysPath: 224 225 Debugging the initial bootstrap of an simulated 226 external process. Ignores load by current 'sys.path'. 227 For debugging of the debug support. 228 229 ignorePydevdCallParam: 230 231 Debugging the initial bootstrap of an simulated 232 external process. Ignores current parameter for 233 load. For debugging of the debug support. 234 235 verbose: 236 237 Display data for user parameters. 238 239 Returns: 240 Creates a proxy instance. 241 242 Raises: 243 passed through exceptions: 244 """ 245 self._verbose = False 246 self._dbg_self= False 247 if sys.modules.get('epyunit.debug.checkRDbg'): 248 self._verbose = epyunit.debug.checkRDbg._verbose 249 self._dbg_self = epyunit.debug.checkRDbg._dbg_self 250 if self._verbose or self._dbg_self: 251 print >>sys.stderr, "RDBG:"+__name__+":options from checkRDbg:rdbgoptions = "+str(epyunit.debug.checkRDbg._rdbgoptions) 252 253 self._itfp = False 254 self._itfs = False 255 self._itfcp = False 256 257 # set initial defaults 258 self.dbgargs = self.dgbargs_default 259 260 for k,v in kargs.items(): 261 if k == 'testflags': 262 try: 263 if epyunit.debug.checkRDbg._testflags: # CLI interaction has priority 264 continue 265 except: 266 pass 267 for tf in v.split(','): 268 if tf == 'ignorePydevd': 269 self._itfp = True 270 elif tf == 'ignorePydevdSysPath': 271 self._itfs = True 272 elif tf == 'ignorePydevdCallParam': 273 self._itfcp = True 274 elif k == 'label': 275 self.label = v 276 elif k == 'verbose': 277 self._verbose = v 278 elif k == 'debug': 279 self._dbg_self= v 280 281 # 282 # fetch CLI values from epyunit.debug.checkRDbg 283 try: 284 if sys.modules.get('epyunit.debug.checkRDbg'): 285 if self._verbose: 286 print >>sys.stderr, "RDBG:"+__name__+":options from checkRDbg:rdbgoptions = "+str(epyunit.debug.checkRDbg._rdbgoptions) 287 288 if epyunit.debug.checkRDbg._rdbgoptions[1]: # _rdbgsrv 289 h,p = epyunit.debug.checkRDbg._rdbgoptions[1].split(':') 290 if h: 291 self.dbgargs['host'] = h 292 if p: 293 self.dbgargs['port'] = int(p) 294 295 if epyunit.debug.checkRDbg._rdbgoptions[3]: # _rdbgroot 296 self.eclipse_glob = epyunit.debug.checkRDbg._rdbgoptions[3] 297 298 if epyunit.debug.checkRDbg._rdbgoptions[4]: # _rdbgsub 299 self.pydevd_glob = epyunit.debug.checkRDbg._rdbgoptions[4] 300 301 if epyunit.debug.checkRDbg._testflags: # CLI interaction has priority 302 for tf in epyunit.debug.checkRDbg._testflags: 303 if tf == 'ignorePydevd': 304 self._itfp = True 305 elif tf == 'ignorePydevdSysPath': 306 self._itfs = True 307 elif tf == 'ignorePydevdCallParam': 308 self._itfcp = True 309 310 except: 311 pass 312 313 314 # check whether running in pydevd.py 315 if not self._itfp and sys.modules.get('pydevd'): # already loaded 316 if self._dbg_self or self._verbose: 317 print "RDBG:"+__name__+":use pydevd.py" 318 319 self.runningInPyDevDbg = True 320 self.pydevdpath = sys.modules.get('pydevd') 321 self.setDebugParams(**kargs) 322 323 else: # has to be loaded, do the initial first-time work 324 if self._dbg_self or self._verbose: 325 print "RDBG:"+__name__+":load pydevd.py" 326 327 self.pydevdpath = self.scanEclipseForPydevd(kargs.get('rootforscan'),**kargs) 328 329 if self.pydevdpath: 330 addPathToSearchPath(os.path.dirname(self.pydevdpath),**{'exist':True,'prepend':True,}) 331 try: 332 import pydevd #@UnresolvedImport #@UnusedImport 333 except Exception as e: 334 raise PyDevRDCException("Load of 'pydevd' failed:"+str(os.path.dirname(self.pydevdpath))+"\n"+str(e)) 335 self.runningInPyDevDbg = True 336 else: 337 self.runningInPyDevDbg = False 338 339 self.setDebugParams(**kargs) 340 341 # starts remote debug immediately 342 self.remotedebug = kargs.get("remotedebug",False) 343 if self.remotedebug: 344 self.startDebug() 345 self._initok=True 346 347 if self._dbg_self: 348 print >>sys.stderr, "RDBG:"+__name__+":dbgargs = "+str(self.dbgargs) 349 print >>sys.stderr, "RDBG:"+__name__+":eclipse_glob = "+str(self.eclipse_glob) 350 print >>sys.stderr, "RDBG:"+__name__+":pydevd_glob = "+str(self.pydevd_glob)
351
352 - def setDebugParams(self,**kargs):
353 """Sets the parameters for debug. 354 355 Args: 356 **kargs: 357 host: 358 359 Hostname where the debug server is running. 360 361 From **pdevd.py**: 362 The user may specify another host, if the debug server 363 is not in the same machine (default is the local host). 364 365 ignore: 366 367 When set to False success is mandatory, else 368 an exception it raised. 369 Set this to True/default, when in production 370 systems. 371 372 port: 373 374 Port the debug server is listening on. 375 From **pdevd.py**: 376 Specifies which port to use for communicating with the 377 server (note that the server must be started in the 378 same port). 379 **Note**: currently it's hard-coded at 5678 380 in the client 381 382 pydevdpath: 383 384 Required path pointing to directory for 385 source of pydevd in PyDev subdirectory tree. 386 387 remotedebug: 388 389 Switches remote debugging support On/Off. 390 391 stderrToServer: 392 393 Sets whether stderr is directed to debugserver. 394 From **pdevd.py**: 395 When this is true, the stderr is passed to the debug server 396 so that they are printed in its console and not in this 397 process console. 398 399 stdoutToServer: 400 401 Sets whether stdout is directed to debugserver. 402 From **pdevd.py**: 403 When this is true, the stdout is passed to the debug server. 404 405 suspend: 406 407 If set to True, stops immediately after settrace() call, 408 else at next valid break-condition. 409 From **pdevd.py**: 410 Whether a breakpoint should be emulated as soon as 411 this function is called. 412 413 trace_only_current_thread: 414 415 From **pdevd.py**: 416 Determines if only the current thread will be traced or all 417 future threads will also have the tracing enabled. 418 419 Returns: 420 The location of pydevd.py 421 422 Raises: 423 AttributeError: 424 425 """ 426 for k,v in kargs.iteritems(): 427 if k=='pydevdpath': 428 pydevdpath=v 429 elif k=='ignore': 430 ignore=v 431 elif k=='remotedebug': 432 remotedebug=v 433 434 elif k=='host': 435 self.dbgargs['host'] = v 436 elif k=='stdoutToServer': 437 self.dbgargs['stdoutToServer'] = v 438 elif k=='stderrToServer': 439 self.dbgargs['stderrToServer'] = v 440 elif k=='port': 441 self.dbgargs['port'] = v 442 elif k=='suspend': 443 self.dbgargs['suspend'] = v 444 elif k=='trace_only_current_thread': 445 self.dbgargs['trace_only_current_thread'] = v 446 elif k=='overwrite_prev_trace': 447 self.dbgargs['overwrite_prev_trace'] = v 448 elif k=='patch_multiprocessing': 449 self.dbgargs['patch_multiprocessing'] = v
450
451 - def scanEclipseForPydevd(self,rootforscan=None, **kargs):
452 """Scans filesystem directory tree of Eclipse for PyDev plugin containing 'pydevd'. 453 454 Scans for 'pydevd' required for subprocess debugging 455 by the Debug-Server of PyDev. See PyDev manual for 456 path reference, the default pattern for 'marketplace' installation is: 457 :: 458 459 eclipse/plugins/org.python.pydev_x.x.x/pysrc/pydevd.py 460 461 in case of drop-in installation 462 :: 463 464 eclipse/dropins/<pydev-dropin-name>/plugins/org.python.pydev_x.x.x/pysrc/pydevd.py 465 466 The matching versions could be varied by glob-expressions. 467 468 The provided parameters match as follows: 469 :: 470 471 rdbgroot := /path/to/eclipse 472 rdbgsub := org.python.pydev_x.x.x/pysrc/pydevd.py 473 474 The glue-hook depends on the type of installation and is determined 475 dynamically: 476 :: 477 478 dropin-install := dropins/<pydev-dropin-name>/plugins 479 market-place-install := plugins 480 481 Basically any path could be used, in particular a rdbgsub directory 482 containing a subset for 'pydevd.py' on a remote machine as stated 483 by the PyDev project for remote debugging of server processes. The 484 filesystem resolution is performed on a local filesystem only, but 485 could be performed by command line start of the headless process 486 on the remote machine too. 487 488 The path is the containment path of the file *pydevd.py* and has to be 489 included in the *sys.path* variable for activation. 490 491 The *scanEclipseForPydevd* method performs a search and returns the 492 absolute path in case of a match. 493 494 The search for the root directory into the Eclipse package installation 495 is performed in the following order and priority: 496 497 1. **parameters** 498 499 Consume call/command line parameters, ENV, and hard/coded. 500 501 Parameter mix by environment variables as present: 502 For the actual main control of environment variables 503 refer to epyunit.checkRDbg.checkAndRemoveRDbgOptions. 504 :: 505 506 (rdbgroot or RDBGROOT) + ( rdbgsub or RDBGSUB ) 507 508 Contains the value for the option '--rdbg-root', 509 either literal or as a 'glob' pattern. 510 The following priorities are applied: 511 512 1. CLI call option 513 2. API call option 514 3. RDBGROOT/RDBGSUB + missing from 515 4. Code defaults 516 517 2. **sys.path** 518 519 Each separate path is tried with the sub-path pattern, 520 first match wins. 521 522 3. **PATH - which eclipse** 523 524 Each separate path is tried with the sub-path pattern, 525 first match wins. 526 527 4. **<HOME>/eclipse/eclipse** 528 529 A convention of the author, where the the path is 530 a symbolic link to the executable. 531 When present, the realpath is evaluated from the link. 532 533 5. **search install directory - dropins** 534 535 When 'ePyUnit' itself is installed as a drop-in within eclipse, 536 the search is performed within the current Eclipse release 537 only:: 538 539 os.path.dirname(__file__) + rdbgsub 540 541 For example:: 542 543 eclipse/dropins/epyunit 544 545 The first match of containing directory for 'pydevd.py' 546 is returned, thus ambiguity in case of multiple occurrences 547 has to be avoided. 548 549 The pattern resolution into the PyDev dir is performed by the steps: 550 :: 551 552 0. <eclipse-root>/plugins/<rdbgsub> 553 554 1. <eclipse-root>/dropins/<rdbgsub> 555 556 2. <eclipse-root>/dropins/*/plugins/<rdbgsub> 557 558 Args: 559 rootforscan: Start directory for tree-scan, either a 560 single, multiple in PATH notation. Each path points 561 to an Eclipse installation directory. 562 563 **kargs: 564 altpat=(<literal>|<glob>): Alternative pattern, varies 'eclipse_glob', 565 and 'pydevd_glob'. 566 567 strict: Provided parameter has to match, else error. 568 569 Default is to try all, when supplied params do not 570 match default values are checked. 571 572 version=(a,b,c): Provide version to be requested. It is recommended 573 to combine this with 'strict'. 574 575 The parameters 'altpat' and 'version' are EXOR. 576 577 version=(a,b,c) 578 a := [0-9]+ 579 b := [0-9]+ 580 b := [0-9]+ 581 582 Returns: 583 The location of pydevd.py 584 585 Raises: 586 AttributeError: 587 588 """ 589 _mlist = [] # list of matches 590 591 _apat = kargs.get('altpat') 592 _vers = kargs.get('version') 593 _pg = self.pydevd_glob 594 595 def _matchsub(_apat,_rfs): 596 # almost literal 597 p = findRelPathInSearchPath(_apat,_rfs) 598 if p: # a match trial 599 return p 600 601 # plugins 602 p = findRelPathInSearchPath("plugins"+os.path.sep+_apat,_rfs) 603 if p: # a match trial 604 return p 605 606 # dropins 607 p = findRelPathInSearchPath("dropins"+os.path.sep+"*"+os.path.sep+"plugins"+os.path.sep+_apat,_rfs) 608 if p: # a match trial 609 return p
610 611 # 0. fetch call parameters which also reflect the resulting command line parameters 612 if _apat and _vers: 613 raise PyDevRDCLoadException("One only supported (version, altpat)=('"+str(_vers)+"', '"+str(_apat)+"')") 614 elif _vers: 615 _apat = "org.python.pydev_"+_vers[0]+"."+_vers[1]+"."+_vers[2]+"*/pysrc/pydevd.py" 616 elif not _apat: 617 if self.pydevd_glob: 618 _apat = self.pydevd_glob 619 else: 620 _apat = _rdbgsub_default 621 622 if not _apat: 623 raise PyDevRDCLoadException("Cannot evaluate rdbgsub-pattern") 624 625 _st = kargs.get('strict',False) 626 627 if type(rootforscan) == NoneType: 628 _rfs = [epyunit.debug.checkRDbg._rdbgroot] 629 elif type(rootforscan) != list: 630 _rfs = [rootforscan] 631 clearPath(_rfs,**self._clrargs) 632 else: 633 _rfs = rootforscan[:] 634 clearPath(_rfs,**self._clrargs) 635 636 if not _rfs: 637 _rfs = [ _rdbgroot_default ] 638 if not _rfs: 639 raise PyDevRDCLoadException("Cannot evaluate rdbgroot for scan") 640 641 p = None 642 643 # 1. call parameter 644 if not self._itfcp: 645 p = _matchsub(_apat,_rfs) 646 if p: 647 return p 648 if _rfs and _st: # has to match immediately when STRICT is choosen 649 return 650 651 # 2. environment RDBGROOT and/or RDBGSUB 652 if not p: 653 try: 654 if _rdbgenv: 655 _r = os.environ['RDBGROOT'] 656 if not _r: 657 _r = _rfs 658 else: 659 _r = [_r,] 660 661 _s = os.environ['RDBGSUB'] 662 if not _s: 663 _s = _apat 664 665 clearPath(_r,**self._clrargs) 666 p = _matchsub(_s,_r) 667 if p: 668 return p 669 elif _r and _s: # has to match immediately when STRICT is choosen 670 return 671 else: 672 _r = _rfs 673 _s = _apat 674 675 except: 676 pass 677 678 # 679 # following are the preset and hard-coded defaults 680 # 681 682 # 3. search 'pydevd.p' by sys.path 683 if not self._itfs and not rootforscan: 684 p = _matchsub('pydevd.py',sys.path) 685 if p: 686 return p 687 688 # 4. search pattern by sys.path 689 if not self._itfs and not rootforscan: 690 p = _matchsub(_apat,sys.path) 691 if p: 692 return p 693 694 # 5. search pattern by PATH 695 if not self._itfs and not rootforscan: 696 p = _matchsub(_apat,os.environ.get('PATH',None)) 697 if p: 698 return p 699 700 # 6. <HOME>/eclipse/eclipse 701 if not p: 702 _r = getHome() 703 _r += os.sep+'eclipse'+os.sep+'eclipse' 704 if os.path.exists(_r): 705 if kargs.get('altpat'): 706 _apat = kargs.get('altpat') 707 if _apat.startswith('eclipse/plugins/'): 708 _apat = _apat[7:] 709 else: 710 _apat = self.pydevd_glob 711 _r = os.path.normpath(os.path.dirname(os.path.realpath(_r))+"/plugins/") 712 713 p = _matchsub(_apat,[_r]) 714 if p: 715 return p 716 717 # 7. search install directory when installed within the 'dropins' directory:: 718 if not p: 719 if os.path.exists(os.path.normpath("../plugins")) and os.path.exists(os.path.normpath("../eclipse")): 720 _r = glob.glob(os.path.normpath("../plugins/"+_pg)) 721 p = _matchsub(_apat,_r) 722 if p: 723 return p
724
725 - def startDebug(self,**kargs):
726 """Starts remote debugging for PyDev. 727 """ 728 for k,v in kargs.items(): 729 if k == 'debug': 730 self._dbg_self = v 731 elif k == 'verbose': 732 self._dbg_self = v 733 734 if self._dbg_self or self._verbose: 735 print >>sys.stderr,"RDBG:debug starting " 736 737 # already loaded 738 if self.runningInPyDevDbg: 739 if self._dbg_self or self._verbose: 740 print >>sys.stderr,"RDBG:dbgargs="+str(self.dbgargs) 741 try: 742 pydevd.settrace( 743 host=self.dbgargs['host'], 744 port=self.dbgargs['port'], 745 stdoutToServer=self.dbgargs['stdoutToServer'], 746 stderrToServer=self.dbgargs['stderrToServer'], 747 suspend=self.dbgargs['suspend'], 748 trace_only_current_thread=self.dbgargs['trace_only_current_thread'] 749 ) 750 #OK-ref: pydevd.settrace(host=None,port=5678,stdoutToServer=False,stderrToServer=False,suspend=False,trace_only_current_thread=True) 751 except Exception as e: 752 raise PyDevRDCException(e) 753 else: 754 raise PyDevRDCException("ERROR:Requires init:self.runningInPyDevDbg="+str(self.runningInPyDevDbg)) 755 if _dbg_self or _dbg_unit: 756 print >>sys.stderr,"RDBG:debug started"
757
758 - def stopDebug(self):
759 """Stops remote debugging for PyDev. 760 """ 761 try: 762 if self.runningInPyDevDbg: 763 pydevd.stopdebug() 764 except Exception as e: 765 raise PyDevRDCException()
766
767 - def setFork(self):
768 """Prepares debugging after fork. 769 """ 770 if self.runningInPyDevDbg: 771 pydevd.settrace_forked() 772 pass
773
774 - def __str__(self):
775 """Prints current remote debug parameters. 776 """ 777 ret = "" 778 ret += "\nPyDevRDC.host = "+str(self.host) 779 ret += "\nPyDevRDC.stdoutToServer = "+str(self.stdoutToServer) 780 ret += "\nPyDevRDC.stderrToServer = "+str(self.stderrToServer) 781 ret += "\nPyDevRDC.port = "+str(self.port) 782 ret += "\nPyDevRDC.suspend = "+str(self.suspend) 783 ret += "\nPyDevRDC.trace_only_current_thread = "+str(self.trace_only_current_thread) 784 ret += "\nPyDevRDC.overwrite_prev_trace = "+str(self.overwrite_prev_trace) 785 ret += "\nPyDevRDC.patch_multiprocessing = "+str(self.patch_multiprocessing) 786 return ret
787
788 - def __repr__(self):
789 """Prints the current representation of remote debug parameters. 790 """ 791 ret = "{" 792 ret += "'host': "+str(self.host) 793 ret += ", 'stdoutToServer': "+str(self.stdoutToServer) 794 ret += ", 'stderrToServer': "+str(self.stderrToServer) 795 ret += ", 'port': "+str(self.port) 796 ret += ", 'suspend': "+str(self.suspend) 797 ret += ", 'trace_only_current_thread': "+str(self.trace_only_current_thread) 798 ret += ", 'overwrite_prev_trace': "+str(self.overwrite_prev_trace) 799 ret += ", 'patch_multiprocessing': "+str(self.patch_multiprocessing) 800 ret += "}" 801 return ret
802 803 804 if not _pderd_inTestMode_suppress_init: 805 if _dbg_self or _dbg_unit: 806 print >>sys.stderr,"RDBG:init:pydevrdc" 807 if not PYDEVD or not PyDevRDC._initok: 808 if _dbg_self or _verbose: 809 print >>sys.stderr, "RDBG:create:epyunit.pydevrdc.PYDEVD" 810 PYDEVD=PyDevRDC() 811 _pydevd = PYDEVD.scanEclipseForPydevd() 812 if not _pydevd: 813 if _dbg_self or _dbg_unit: 814 print >>sys.stderr,"RDBG:Missing, pydevd.py not found" 815 else: 816 print >>sys.stderr,"RDBG:Remote debug deactive, missing pydevd.py - not found" 817 else: 818 if _dbg_self: 819 print >>sys.stderr,"RDBG:found pydevd.py:"+str(_pydevd) 820 if _dbg_unit: 821 print >>sys.stderr,"RDBG:found pydevd.py" 822 addPathToSearchPath(os.path.dirname(_pydevd),**{'exist':True,'prepend':True,}) 823 import pydevd #@UnresolvedImport 824 pass 825 pass 826