def main(): parser = argparse.ArgumentParser(description=''' Accept requests from remote services on your local machine during debugging ''') parser.add_argument('--url', metavar='URL', type=str, help='External URL, if already obtained', default=None, required=False) args = parser.parse_args() proxy_link = Array('c', 50) if args.url: proxy_link.value = bytes(args.url, 'utf-8') else: port_forwarding_proc = Process(target=run_port_forwarding, args=(proxy_link, )) port_forwarding_proc.start() app_proc = Process(target=run_app, args=(proxy_link, )) app_proc.start()
import os import time from multiprocessing import Array, Process names = Array('c', range(20)) # range(20) 只是指定一个字符数组的长度大小 def add_name(name): print(os.getpid(), '子进程修改前names:', names.value) names.value = name.encode() # 在子进程修改主进程变量 print(os.getpid(), '子进程修改后names:', names.value) time.sleep(2) if __name__ == '__main__': names.value = b'Disen' # names是Array类对象,存储字节类型的数据 p = Process(target=add_name, kwargs={'name': 'ABC'}) p.start() p.join() print('主进程结束--names: ', names.value)
voteIds.append(line.find("input")['value']) option_names.append(line.find("label").get_text()) options += 1 i = 1 for name in option_names: print(str(i) + ") " + str(name)) i += 1 choice = input('Select an option: ') if int(choice) < 0 or int(choice) > len(voteIds): print("Invalid option") else: #s = requests.Session() url.value = str.encode(URL) #data.value = str.encode("security-token=" + security_token + "&" + auth_token + "=&options=" + voteIds[int(option)-1]) sec_key.value = str.encode(security_token) # auth_key.value = str.encode(auth_token) option.value = int(voteIds[int(choice) - 1]) start.value = 1 print("job started") for i in range(0, int(NumOfProcs)): if i < procs: continue # process = Process(target=vote, kwargs={"offSet": i*PROXIES_PER_PROCESS,"proxy_list":proxy_list,"url":url,"sec_key":sec_key,"auth_key":auth_key,"option":option,"PROXIES_PER_PROCESS":PROXIES_PER_PROCESS,"start":start}) process = Process(target=vote, kwargs={ "offSet": i * PROXIES_PER_PROCESS, "proxy_list": proxy_list,
def main(): import argparse p = argparse.ArgumentParser(prog=_PROGRAM_NAME, description=("Templating engine for text-based status " "bars.")) p.add_argument("-c", "--config", type=argparse.FileType('r'), help=("Path to config file.")) p.add_argument("--xmobar", action='store_true', default=False, help=("If true, run xmobar and output stats that way.")) p.add_argument("--version", action="version", version="%(prog)s v{}".format(_VERSION)) p.add_argument("--verbose", default=False, action="store_true", help=("If set, show more log messages.")) args = p.parse_args() setup_logging(verbose=args.verbose) logging.debug("Starting {} version: {}".format(_PROGRAM_NAME, _VERSION)) try: config = ConfigFile(args.config) except ConfigParseError as e: logging.critical('Error loading config file. {}'.format(e)) return 1 stop_main_event = Event() stop_worker_event = Event() stdin_updated_lock = Lock() # Make array 2x larger in case line is all unicode most_recent_stdin_line = Array(c_char, _MAX_STDIN_LINE_LEN*2) most_recent_stdin_line.value = bytes("default stdin value", encoding="utf-8") if config.output_program is not None: if config.output_program == 'xmobar': output_filenames = start_xmobar(stop_worker_event) elif config.output_program == 'none': pass else: raise ConfigParseError('Unrecognised output_program {}'.format(repr(config.output_program))) run_startup_animation(output_filenames) workers = [ Process(target=continually_output_status, args=( most_recent_stdin_line, stdin_updated_lock, config, output_filenames, stop_worker_event,)), Process(target=read_stdin_to_value, args=( most_recent_stdin_line, stdin_updated_lock, stop_main_event, stop_worker_event,)), ] for w in workers: w.start() while not stop_main_event.is_set(): time.sleep(1) try: stdin_updated_lock.release() except ValueError: pass stop_worker_event.set() for w in workers: w.join()
from multiprocessing import Process, Array import time # 创建共享内存 # shm = Array('i', [1,2,3,4]) # 开辟5个整型空间 # shm = Array('i', 5) # 存入字节串 shm = Array('c', b'hello') def fun(): for i in shm: time.sleep(0.5) print(i) shm[0] = b'z' # 修改共享内存 p = Process(target=fun) p.start() p.join() for i in shm: print(i) print(shm.value) # 打印字符串 shm.value = b'hi' print(shm.value) # 打印字符串
# coding=utf-8 import time from ctypes import c_char from multiprocessing import Process, Value, Manager, Array import argparse if __name__ == '__main__': volume = Value('i', 0) playing = Value('i', 1) text = Array(c_char, "*" * 1000) text2 = Array(c_char, "*" * 100) text.value = "" text2.value = "" parser = argparse.ArgumentParser(description='Control a local squeezebox') parser.add_argument('--mac', dest='mac', action='store', default=None, help='MAC Address of the player to control') parser.add_argument('--port', dest='port', action='store', default=9090, help='port number of the LMS Server') parser.add_argument('--host', dest='host', action='store', default="127.0.0.1", help='hostname or IP of the LMS Server') parser.add_argument('--a', dest='channel_a', action='store', default=27, help='Rotary Encoder Channel A BCM PIN')
from Bio import SeqIO from Bio.Blast.Applications import NcbiblastxCommandline from Bio.PDB.PDBParser import PDBParser from Bio.PDB.PDBList import PDBList from Bio.PDB.Polypeptide import PPBuilder from Bio.PDB.Polypeptide import is_aa from fileops import InsertFolderSeparator #Buffered SyncPrint allows for more controlled printing when #running parallel processing. When Set to buffered, output is not printed directly to console, #but to a buffer which can be flushed (printed) at desired points or intervals. g_SyncPrintBuffer_max = 20000 #buffer size in number of chars g_SyncPrintBuffered = Value( 'i', 0 ) #YES == 1, NO == 0 g_SyncPrintBuffer = Array( 'c', " "*g_SyncPrintBuffer_max ) g_SyncPrintBuffer.value = "" g_SyncPrintBuffer_overflow = Value( 'i', 0) #Overflow indicator #Pass the return value to a thread as an initializer argument def GetSyncPrintBufferForThread(): global g_SyncPrintBuffered, g_SyncPrintBuffer, g_SyncPrintBuffer_overflow return (g_SyncPrintBuffered, g_SyncPrintBuffer, g_SyncPrintBuffer_overflow) #In the Thread, call this method with the return value of GetSyncPrintBufferForThread() def SetSyncPrintBufferInThread( aBuffer): global g_SyncPrintBuffered, g_SyncPrintBuffer, g_SyncPrintBuffer_overflow g_SyncPrintBuffered = aBuffer[ 0] g_SyncPrintBuffer = aBuffer[ 1] g_SyncPrintBuffer_overflow = aBuffer[ 2]
# coding=utf-8 import time from ctypes import c_char from multiprocessing import Process, Value, Manager, Array import argparse if __name__ == '__main__': volume = Value('i', 0) playing = Value('i', 1) text = Array(c_char, "*" * 1000) text2 = Array(c_char, "*" * 100) text.value = "" text2.value = "" parser = argparse.ArgumentParser(description='Control a local squeezebox') parser.add_argument('--mac', dest='mac', action='store', default=None, help='MAC Address of the player to control') parser.add_argument('--port', dest='port', action='store', default=9090, help='port number of the LMS Server') parser.add_argument('--host', dest='host', action='store',