Hallo,
die Absicht hinter dem Code ist offentsichtlich
leider funktioniert es so nicht.
nehme ich den Thread heraus, funktioniert atexit prima
Ich habe offene Schnittstellen, Datei im Thread und will eine
Funktion haben, die zum Schluß aufräumt und Resourcen freigibt.
Habt ihr eine Idee wie ich das machen könnte?
1 | #!/usr/bin/env python
|
2 |
|
3 | import threading, atexit, time, sys
|
4 |
|
5 | def foo(msg):
|
6 | print "stop", msg
|
7 |
|
8 | atexit.register(foo, "from main")
|
9 |
|
10 | def bar():
|
11 | atexit.register(foo, "from bar")
|
12 | while True:
|
13 | time.sleep(2)
|
14 | print ">>> thread"
|
15 |
|
16 | t = threading.Thread(target=bar).start()
|
17 |
|
18 | cnt = 0
|
19 | while True:
|
20 | time.sleep(1)
|
21 | print "main"
|
22 | cnt += 1
|
23 | if cnt == 2:
|
24 | sys.exit(1)
|
25 |
|
26 | #t.join()
|