Ich frage mich, ob es möglich ist, automatisch nur bestimmte Codeabschnitte in vim zu falten (speziell für Python-Dateien).
Ich verwende derzeit die Einzugsmethode. Und ich möchte einen eingerückten Block nur dann falten, wenn der Header mit einem Muster übereinstimmt.
Wenn ich zum Beispiel in einer Datei mit dieser Funktion bin, möchte ich, dass alle Blöcke, die mit Example: oder References: beginnen, automatisch gefaltet werden, aber ich möchte nicht, dass etwas anderes gefaltet wird.
Gibt es eine einfache Möglichkeit, dies zu tun?
def spawn_background_process(func, *args, **kwargs):
"""
Run a function in the background
(like rebuilding some costly data structure)
References:
http://stackoverflow.com/questions/2046603/is-it-possible-to-run-function-in-a-subprocess-without-threading-or-writing-a-se
http://stackoverflow.com/questions/1196074/starting-a-background-process-in-python
http://stackoverflow.com/questions/15063963/python-is-thread-still-running
Args:
func (function):
CommandLine:
python -m utool.util_parallel --test-spawn_background_process
Example:
>>> # DISABLE_DOCTEST
>>> from utool.util_parallel import * # NOQA
>>> import utool as ut
>>> import time
>>> from os.path import join
>>> # build test data
>>> fname = 'test_bgfunc_output.txt'
>>> dpath = ut.get_app_resource_dir('utool')
>>> ut.ensuredir(dpath)
>>> fpath = join(dpath, fname)
>>> # ensure file is not around
>>> sleep_time = 1
>>> ut.delete(fpath)
>>> assert not ut.checkpath(fpath, verbose=True)
>>> def backgrond_func(fpath, sleep_time):
... import utool as ut
... import time
... print('[BG] Background Process has started')
... time.sleep(sleep_time)
... print('[BG] Background Process is writing')
... ut.write_to(fpath, 'background process')
... print('[BG] Background Process has finished')
... #raise AssertionError('test exception')
>>> # execute function
>>> func = backgrond_func
>>> args = (fpath, sleep_time)
>>> kwargs = {}
>>> print('[FG] Spawning process')
>>> threadid = ut.spawn_background_process(func, *args, **kwargs)
>>> assert threadid.is_alive() is True, 'thread should be active'
>>> print('[FG] Spawned process. threadid=%r' % (threadid,))
>>> # background process should not have finished yet
>>> assert not ut.checkpath(fpath, verbose=True)
>>> print('[FG] Waiting to check')
>>> time.sleep(sleep_time + .1)
>>> print('[FG] Finished waiting')
>>> # Now the file should be there
>>> assert ut.checkpath(fpath, verbose=True)
>>> assert threadid.is_alive() is False, 'process should have died'
"""
import utool as ut
func_name = ut.get_funcname(func)
name = 'mp.Progress-' + func_name
proc_obj = multiprocessing.Process(target=func, name=name, args=args, kwargs=kwargs)
#proc_obj.isAlive = proc_obj.is_alive
proc_obj.start()
return proc_obj