File: bootstrap.py

package info (click to toggle)
python-pyqtgraph 0.13.7-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,068 kB
  • sloc: python: 54,043; makefile: 129; ansic: 40; sh: 2
file content (36 lines) | stat: -rw-r--r-- 1,346 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""For starting up remote processes"""
import importlib
import os
import pickle
import sys

if __name__ == '__main__':
    if hasattr(os, 'setpgrp'):
        os.setpgrp()  ## prevents signals (notably keyboard interrupt) being forwarded from parent to this process
    #name, port, authkey, ppid, targetStr, path, pyside = pickle.load(sys.stdin.buffer)
    opts = pickle.load(sys.stdin.buffer)
    #print "key:",  ' '.join([str(ord(x)) for x in authkey])
    path = opts.pop('path', None)
    if path is not None:
        if isinstance(path, str):
            # if string, just insert this into the path
            sys.path.insert(0, path)
        else:
            # if list, then replace the entire sys.path
            ## modify sys.path in place--no idea who already has a reference to the existing list.
            while len(sys.path) > 0:
                sys.path.pop()
            sys.path.extend(path)

    qt_lib = opts.pop('qt_lib', None)
    if qt_lib is not None:
        globals()[qt_lib] = importlib.import_module(qt_lib)
    
    targetStr = opts.pop('targetStr')
    try:
        target = pickle.loads(targetStr)  ## unpickling the target should import everything we need
    except:
        print("Current sys.path:", sys.path)
        raise
    target(**opts)  ## Send all other options to the target function
    sys.exit(0)