mirror of
https://github.com/autistic-symposium/web3-starter-py.git
synced 2025-05-17 14:10:21 -04:00
💾
This commit is contained in:
parent
7cb7a479f6
commit
69bb4175f1
124 changed files with 20 additions and 15 deletions
39
boilerplates/concurrency/daemon_example.py
Normal file
39
boilerplates/concurrency/daemon_example.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import time
|
||||
import sys
|
||||
import multiprocessing
|
||||
|
||||
|
||||
def daemon():
|
||||
p = multiprocessing.current_process()
|
||||
print('Starting: {}, {}'.format(p.name, p.pid))
|
||||
|
||||
sys.stdout.flush()
|
||||
time.sleep(1)
|
||||
print('Exiting : {}, {}'.format(p.name, p.pid))
|
||||
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
def non_daemon():
|
||||
p = multiprocessing.current_process()
|
||||
print('Starting: {}, {}'.format(p.name, p.pid))
|
||||
|
||||
sys.stdout.flush()
|
||||
print('Exiting : {}, {}'.format(p.name, p.pid))
|
||||
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
d = multiprocessing.Process(name='daemon', target=daemon)
|
||||
d.daemon = True
|
||||
|
||||
n = multiprocessing.Process(name='non-daemon', target=non_daemon)
|
||||
n.daemon = False
|
||||
|
||||
d.start()
|
||||
time.sleep(1)
|
||||
n.start()
|
Loading…
Add table
Add a link
Reference in a new issue