我想用multiprocessing
模块来完成这个.
当我这样做时,像:
$ python my_process.py
Run Code Online (Sandbox Code Playgroud)
我启动一个父进程,然后让父进程生成一个子进程,
然后我希望父进程退出,但子进程继续工作.
请允许我写一个错误的代码来解释自己:
from multiprocessing import Process
def f(x):
with open('out.dat', 'w') as f:
f.write(x)
if __name__ == '__main__':
p = Process(target=f, args=('bbb',))
p.daemon = True # This is key, set the daemon, then parent exits itself
p.start()
#p.join() # This is WRONG code, just want to exlain what I mean.
# the child processes will be killed, when father exit
Run Code Online (Sandbox Code Playgroud)
那么,如何在父进程完成时启动一个不会被杀死的进程?
20140714
嗨,你们
我的朋友告诉我一个解决方案......
我只是想...
无论如何,只是让你看看:
import os
os.system('python your_app.py&') …
Run Code Online (Sandbox Code Playgroud) 我阅读了collections.namedtuple
今天的官方文档并_tuple
在__new__
方法中找到了.我没有找到_tuple
定义的位置.
您可以尝试在Python中运行下面的代码,它不会引发任何错误.
>>> Point = namedtuple('Point', ['x', 'y'], verbose=True)
class Point(tuple):
'Point(x, y)'
__slots__ = ()
_fields = ('x', 'y')
def __new__(_cls, x, y):
'Create a new instance of Point(x, y)'
return _tuple.__new__(_cls, (x, y)) # Here. Why _tuple?
Run Code Online (Sandbox Code Playgroud)
更新:有什么好处
from builtins import property as _property, tuple as _tuple
Run Code Online (Sandbox Code Playgroud)
是不是只是为了让tuple
是一个受保护的价值?我对吗?
我执行update
方法:
# connect db to get `conn`
# get metadate which is table `account`
u = account.update().where(account.c.ID == 9).values(USERNAME='k9')
r = conn.execute(u)
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得update
成功或失败?我检查了文档,但没有找到...
或者也许我只是不在乎这个?
r
是一个ResultProxy
自动update
提交和关闭的操作。
谢谢:)
附加
谢谢@Lucas Kahlert 的回答,好点!
rowcount
满足我的问题的情况。
This attribute returns the number of rows matched,
which is not necessarily the same as the number of rows that were actually modified
In [7]: u = account.update().\
where( and_((account.c.ID == 4), (account.c.PWD =='4297f44b1'))).\
values(PWD='hahahaha')
In [8]: print …
Run Code Online (Sandbox Code Playgroud) 我有这个:
>>> 1 in (i for i in range(0, 5))
True
>>> 2 in (i for i in range(0, 5))
True
Run Code Online (Sandbox Code Playgroud)
之后:
>>> gen = (i for i in range(0, 5))
>>> 1 in gen
True
>>> 3 in gen
True
>>> 2 in gen
False
Run Code Online (Sandbox Code Playgroud)
关键字是否in
有效:
3 in gen
Run Code Online (Sandbox Code Playgroud)
等于:
j = 3
for i in gen:
if i == j:
return True
else:
return False
Run Code Online (Sandbox Code Playgroud)
但在for循环之后,请勿再次将迭代器重置为FIRST.
是对的吗?
我不知道之间的区别spring-boot-maven-plugin
和maven-compiler-plugin
。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
这是否意味着Spring Boot Maven Plugin
包括maven-compiler-plugin
?
我只是使用Spring Boot Maven Plugin
就可以,不需要添加2个插件??
python ×3
in-operator ×1
iterator ×1
java ×1
maven ×1
maven-3 ×1
namedtuple ×1
spring ×1
spring-boot ×1
sqlalchemy ×1